GoTo Records help

sonny

Registered User.
Local time
Today, 10:50
Joined
Mar 2, 2004
Messages
140
I have this code on a popup form. The user selects from the Combo2 then clicks find. This code works but it returns all records having data in either CatCode or CatCode2 fields or my Main form. I want it to search those 2 fields and return only records that match the value of Combo2 on my popup form. Not any value...


Code:
Private Sub FindRecords_Click()
On Error GoTo Err_Command3_Click
    Dim flt As String
    Dim rs As DAO.Recordset
    Dim lRecordCount As Long
    flt = "[CatCODE] Or [CatCode2] = '" & Me.Combo2 & "'"
    DoCmd.Close
    DoCmd.OpenForm "frmMainData", acNormal, , flt, acFormEdit
Debug.Print flt
  Set rs = Forms!frmMainData.RecordsetClone
    
  If Not (rs.EOF) Then
     rs.MoveLast
  End If

  lRecordCount = rs.RecordCount
  If lRecordCount > 1 Then
    MsgBox lRecordCount & " records found with that Code, Please make sure your viewing the correct record!" & vbCr & vbCr & _
    "To do so, use the navigation buttons located at the bottom left of the form. "
    
  End If
    
  Set rs = Nothing
Exit_Command3_Click:
    Exit Sub

Err_Command3_Click:
    MsgBox Err.Description
    Resume Exit_Command3_Click
    
End Sub
 
Last edited:
Actually, what I think your where condition is returning is any value for CatCODE OR all values where CatCode2 = Me.Combo2...

Try this:

flt = "[CatCODE] = '" & Me.Combo2 & "'" & " Or [CatCode2] = '" & Me.Combo2 & "'"

(I think the syntax is correct...)
 
I gave it a try but it only returns a blank record. Is there a different method to do this?
 
Access97 Help says:

The following example opens the Employees form in Form view and displays only records with King in the LastName field. The displayed records can be edited, and new records can be added.

DoCmd.OpenForm "Employees", , ,"LastName = 'King'"

Try the statement without the brackets []...
 

Users who are viewing this thread

Back
Top Bottom