Results 1 to 7 of 7
  1. #1
    Join Date
    Aug 2004
    Posts
    7

    Unhappy Unanswered: 'Find' form not finding records

    I have a form called (Find Employee) set up that is only used to find records from a table (BadgeData) and returns the record on another form (IndivData). On the Find Employee form, there are three text boxes that are unbound but exist in the BadgeData table(Badge Number, FName, & LName). I created a command button (btnFindBadgeData) to use the data entered on the Find Employee form, search the BadgeData table and return the record on the IndivData form. The data I am using to test with I pulled from the record source table...so I know the data is there; however, no records are being returned!!

    I am new to coding and it took me quite a while to get this. Can someone take a look and let me know what I'm doing wrong, or perhaps point me to a post that could help me out! Thanks!!

    Code:
    Private Sub btnFindBadgeData_Click()
    On Error GoTo Err_btnFindBadgeData_Click
    
        Dim stDocName As String
        Dim stLinkCriteria As String
    
        stDocName = "IndivData"
        If (stLinkCriteria = "[CardNum]=" & "'" & Me![CardNum] & "'" _
            & "OR [FName]=" & "'" & Me![FName] & "'" _
            & "OR [LName]=" & "'" & Me![LName] & "'") Then
            DoCmd.OpenForm stDocName, , , stLinkCriteria
        Else
            Beep
            MsgBox "No employee data was found." _
                & vbCrLf & vbCrLf _
                & "Please try again.", vbInformation
            CardNum.SetFocus
        End If
            Me.[CardNum] = Null
            Me.[LName] = Null
            Me.[FName] = Null
    
    Exit_btnFindBadgeData_Click:
        Exit Sub
    
    Err_btnFindBadgeData_Click:
        MsgBox Err.Description
        Resume Exit_btnFindBadgeData_Click
        
    End Sub

  2. #2
    Join Date
    Sep 2004
    Posts
    10
    Are you getting your message box? or an empty form?

  3. #3
    Join Date
    Aug 2004
    Posts
    7
    The message box.

  4. #4
    Join Date
    Sep 2004
    Posts
    10
    have you tried determining what the criteria is--before building the string? (rather than using "OR")....for instance:

    Code:
       
        Dim stDocName As String
        Dim stLinkCriteria As String
        Dim stCardNum as string
        Dim stFName as string
        Dim stLName as string
        
        stDocName = "IndivData"
        stCardNum=Me![CardNum]
        stFName=Me![FNname]
        stLName=Me![LName]
        
        if stCardNum <> "" then
              stLinkCriteria=stCardNum
        else if stFName <> "" then
              stLinkCriteria =stFName
        else if stLName <> "" then
              stLinkCriteria = stLName
        end if
    
        If stLinkCriteria <> " " then
            DoCmd.OpenForm stDocName, , , stLinkCriteria
        Else
    may work...depending on the fields you are searching...

  5. #5
    Join Date
    Aug 2004
    Posts
    7

    Maybe..

    Well, once again, I'm fairly new to coding, so I'm still in LEARN mode. From the example above, will it allow the user to search using more than one field (text box)? That was one of my main reasons for using OR. I need to be able to search using any combination of the fields provided on the search form.

  6. #6
    Join Date
    Sep 2003
    Location
    MI
    Posts
    3,713
    I would really look at redesigning your logic ... You want to test a recordset for your messagebox popup ...
    Back to Access ... ADO is not the way to go for speed ...

  7. #7
    Join Date
    Aug 2004
    Posts
    7
    Quote Originally Posted by M Owen
    ... You want to test a recordset for your messagebox popup ...
    I'm sure your suggestion was probably very simple, but it went entirely over my head! I have no idea what that means let alone how I would accomplish it.

Posting Permissions

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