Results 1 to 3 of 3

Thread: sql search

  1. #1
    Join Date
    May 2004
    Posts
    86

    Unanswered: sql search

    im trying to search my form with one button. I have a text box called text5. Now the user will enter a id and i want to search my form and go to that record. Below is the code i used... when i click the search button it does nothing much help thanks. CFR_EHPID is the feild im trying to find and text5 is the text box on the form...

    Private Sub Command103_Click()
    Dim strSQL As String
    strSQL = "SELECT * FROM qryCFR_History Where CFR_EHPID = Me.Text5"
    End Sub

  2. #2
    Join Date
    Feb 2005
    Location
    England.
    Posts
    232
    I think you're going to need to get a variable to hold text5.value as you can't reference this from within the SQL, to my knowledge.

  3. #3
    Join Date
    May 2004
    Posts
    86

    ok i want to search by something

    ok i wnat to search by two text fields.... im trying to use the code below and it isnt working. It only searches by eho id and not offset


    Dim strStudentRef As String
    Dim strSearch As String

    If IsNull(Me![Text5]) Or (Me![Text5]) = "" Then
    MsgBox "Please enter a EHP ID", vbOKOnly, "Invalid Search Criterion!"
    Me![Text5].SetFocus
    Exit Sub
    End If

    DoCmd.ShowAllRecords
    DoCmd.GoToControl ("CFR_EHPID")
    DoCmd.FindRecord Me!Text5
    Text5.SetFocus

    strSearch = Text5.text
    CFR_EHPID.SetFocus
    strStudentRef = CFR_EHPID.text

    If strStudentRef = strSearch Then
    MsgBox "History Found For EHP ID#: " & strSearch & ""
    CFR_EHPID.SetFocus

    DoCmd.RunSQL


    ElseIf strStudentRef <> strSearch Then
    DoCmd.ShowAllRecords
    DoCmd.GoToControl ("CFR_PATOFFSET")
    DoCmd.FindRecord Me!Text169
    Text169.SetFocus

    strSearch = Text169.text
    CFR_EHPID.SetFocus
    strStudentRef = CFR_PATOFFSET.text

    If strStudentRef = strSearch Then
    MsgBox "Matching Record Found!", vbOKOnly + vbExclamation, "Message"
    Text169.SetFocus
    Text169 = ""

    Else
    MsgBox "No Matching Record Found. Please Try Again!", vbOKOnly + vbInformation, "Message!"
    Text5.SetFocus
    Text5 = ""

    End If
    End If
    End Sub

Posting Permissions

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