Results 1 to 2 of 2
  1. #1
    Join Date
    Jan 2006

    Question Unanswered: Search Help Please

    I am new to this board and also new to access so I will try to be detailed as possible. I have also been reading other posts and have finally at least got a search, but just not like I want.
    I have a database called Master Name Index. This database has approx. 10K names in it. I want to search the records by FirstName, LastName, and DOB.
    I would like to create a form that has a text box, button, and list box. I would also like to have the user type in the Text box a first name, last name, or dob and then the results show up in the list box so that the user can click on the correct result and go to the form containing the records(Master Name Index).

    Main Form is Called Master Name Index
    Fields I would like to search are called LastName, FirstName, and DOB.

    I am currently using this code but it does not allow the results to go to a list box. Would it be possible to use this code or would I have to use a differant one.
    HTML Code:
    Private Sub Command2_Click()
    On Error GoTo Err_Command61_Click
    Dim stDocName As String
    Dim stLinkCriteria As String
    stDocName = "Master Name Database"
    stLinkCriteria = "[LastName] LIKE " & "'*" & [Text0] & "*'"
    DoCmd.OpenForm stDocName, , , stLinkCriteria
    With Me
    .OrderByOn = True
    .OrderBy = "LastName"
    End With
    Exit Sub
    MsgBox Err.Description
    Resume Exit_Command61_Click
    End Sub

  2. #2
    Join Date
    Feb 2006
    Houston, TX USA
    stLinkCriteria = "[LastName] LIKE " & "'*" & [Text0] & "*'"
    would be

    stLinkCriteria = "[LastName] = " & chr(34) & [TextControl0] & chr(34) & _
    "[FirstName] =" & chr(34) & [TextControl1] & chr(34) & _
    '[DOD] =" & "#" & [DateControl01] & "#"

    As a matter of efficienct Access VBA coding, do not use spaces in source or object name, it complicates codes. Also consider using the "Hungarian" naming convention for controls. Days after codiong, the programmer will forget the datatype of a control. Google "Hungarian naming convention" for the (prefixt) notation.

Posting Permissions

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