+ Reply to Thread
Results 1 to 8 of 8

Thread: Search from help

  1. #1
    Barn Regular Colper is an unknown quantity at this point Colper's Avatar
    Join Date
    Dec 2009
    Posts
    67
    Rep Power
    3

    Search Form, help please.

    I need help please.

    I need to create a form to search my DB by: ANumber, ID2Number, LastName, and DateOfBirth. Can someone please guide me on how to do it.
    I have created the form with the search boxes mentioned and what I want is to be able to search by multiple or single entries. For example if someone inputs ANumber it will find it. Or if LastName and DOB it will find records with that criteria, but not DOB alone (If possible)

    I also need a message if all the textbobxes to search are blank.

    This is what I have so far:

    Private Sub SearchCmd_Click()
    On Error GoTo Err_SearchCmd_Click

    Dim stDocName As String
    Dim stLinkCriteria As String

    stDocName = "frmAdpEdit"

    If Me.ANumberTxt1 & "" = "" Then
    MsgBox "PLease enter A-Number"
    Me.ANumberTxt1.SetFocus
    Exit Sub

    Else
    If Not IsNull([ANumberTxt1]) Then
    stLinkCriteria = "[ANumb]=" & "'" & Me![ANumberTxt1] & "'"
    End If
    End If


    DoCmd.OpenForm stDocName, , , stLinkCriteria

    If IsNull(Forms!frmAdpEdit!ANumb) Then
    DoCmd.Close acForm, "frmAdpEdit"
    MsgBox "Recod Does Not Exist"
    End If


    Exit_SearchCmd_Click:
    Exit Sub

    Err_SearchCmd_Click:
    MsgBox Err.Description
    Resume Exit_SearchCmd_Click

    End Sub

    It works fine but I need the other textboxes to be seaechable.

    Thank you.
    Last edited by Colper; December 16th, 2009 at 10:20 PM.

  2. #2
    Barn Enthusiast sbenj69 is a jewel in the rough sbenj69 is a jewel in the rough sbenj69 is a jewel in the rough sbenj69 is a jewel in the rough sbenj69's Avatar
    Join Date
    Mar 2008
    Location
    The frigid northern plains
    Posts
    432
    Rep Power
    7
    Join our Folding team: DeveloperBarn Folding
    -----------------------------------
    Folding Stats - Stanford University
    Folding Stats - Extreme Over-Clocking
    Folding Stats - Kakao Stats
    Folding Stats - Xtreme CPU

    -----------------------------------

  3. #3
    Barn Regular Colper is an unknown quantity at this point Colper's Avatar
    Join Date
    Dec 2009
    Posts
    67
    Rep Power
    3

    Thanks for your help. I had already looked into that thread, is very useful. But it does not give me the VBA code like the one I pasted here.

  4. #4
    Lightning Master AOG123 is a jewel in the rough AOG123 is a jewel in the rough AOG123 is a jewel in the rough AOG123 is a jewel in the rough AOG123's Avatar
    Join Date
    Mar 2008
    Location
    Fortress Of Solitude
    Posts
    394
    Rep Power
    7

    Hi, haven't been around here for a while, popped on the other day and this post was of particular interest. After a fair bit of messing around i have come to the conclusion which first hit me. This kind of criteria filter is best suited to a form which is query based. The query will hold the form text box parameters. Actually very straight forward. Have you tried this?
    If i helped you, make me famous by clicking the

  5. #5
    Barn Regular Colper is an unknown quantity at this point Colper's Avatar
    Join Date
    Dec 2009
    Posts
    67
    Rep Power
    3

    No, I don't know how to.

    Thank you!

  6. #6
    Lightning Master AOG123 is a jewel in the rough AOG123 is a jewel in the rough AOG123 is a jewel in the rough AOG123 is a jewel in the rough AOG123's Avatar
    Join Date
    Mar 2008
    Location
    Fortress Of Solitude
    Posts
    394
    Rep Power
    7

    Your frmAdpEdit record source will be a query. The Query will contain references to the txt boxes on you form i.e.
    Code:
    Like [Forms]![UnboundForm]![ANumberTxt1] & "*" 
    Full example based on the info you provided,

    Code:
    SELECT DataTable.ANumb, DataTable.ID2Number, DataTable.LastName, DataTable.DateOfBirth
    FROM DataTable
    WHERE (((DataTable.ANumb) Like [Forms]![UnboundForm]![ANumberTxt1] & "*") AND ((DataTable.ID2Number) Like [Forms]![UnboundForm]![txtID2Number] & "*") AND ((DataTable.LastName) Like [Forms]![UnboundForm]![txtLastName] & "*") AND ((DataTable.DateOfBirth) Like [Forms]![UnboundForm]![txtDateOfBirth] & "*"));
    
    Your form command button will then read the results of this query when opening the frmAdpEdit

    From the VBA you provided a effective sollution is as follows,

    Notice i am not inlcuding DOB in the first Null statement, also note i am using "AND"

    Code:
    Dim stDocName As String
    Dim stLinkCriteria As String
    
        If IsNull(ANumberTxt1) And IsNull(txtID2Number) And IsNull(txtLastName) Then
          MsgBox "Please Enter More Search Criteria"
            Me.ANumberTxt1.SetFocus
        Exit Sub
    Else
        stDocName = "frmAdpEdit"
          DoCmd.OpenForm stDocName, , , stLinkCriteria
        End If
      
        If IsNull(Forms!frmAdpEdit!ANumb) Then
          DoCmd.Close acForm, "frmAdpEdit"
            MsgBox "Recod Does Not Exist"
    End If
    
    This simply make a DOB seach on its own move to the MsgBox and Exit the sub.

    I have attached an example to help.

    Regards AOG
    Attached Files
    Last edited by AOG123; December 19th, 2009 at 11:01 AM.
    If i helped you, make me famous by clicking the

  7. #7
    Barn Regular Colper is an unknown quantity at this point Colper's Avatar
    Join Date
    Dec 2009
    Posts
    67
    Rep Power
    3

    OMG, I can't believe you did this for me. What a xmas present. AOG123, God bless you I wish you the best.

    Merry Christmas!!!!!
    Last edited by Colper; December 22nd, 2009 at 09:04 AM.

  8. #8
    Barn Regular Colper is an unknown quantity at this point Colper's Avatar
    Join Date
    Dec 2009
    Posts
    67
    Rep Power
    3

    AOG123, I just tried to implement your sample into my DB and I am having trouble. The problem is that my table has more than four fields and I need the query you created for me to be able to have the same fields as my table, but those four will be the searcable ones.

    When I open the frmAdpEdit on the DB I implemented your sample. I only see the 4 searchable fields and the rest of the fileds are like this: "#Name?"

+ Reply to Thread

Similar Threads

  1. SQL Search for last field?
    By Colmag in forum Microsoft Access
    Replies: 10
    Last Post: August 13th, 2009, 04:03 PM
  2. SQL Search in VBA
    By Colmag in forum Microsoft Access
    Replies: 9
    Last Post: July 27th, 2009, 04:04 PM
  3. Alphabet search??
    By Centurion in forum ASP Development
    Replies: 5
    Last Post: February 22nd, 2009, 10:59 PM
  4. search,add and edit in asp.net
    By guddu in forum .NET Development
    Replies: 34
    Last Post: January 15th, 2009, 02:53 PM
  5. picture search
    By Centurion in forum ASP Development
    Replies: 3
    Last Post: December 2nd, 2008, 09:06 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

SEO by vBSEO