Solved

RECORDSET FIND WITH 2 FIELDS

Posted on 2001-08-09
3
743 Views
Last Modified: 2008-02-01
Does anyone know the syntax to using the find method with two fields in the criteria. This is what I currently have but it does not like the syntax:
rsAppliedPayment.Find "PaymentID = " & TempPaymentId & ",Invoice = " & rs!INVOICE, , adSearchForward

I also tried this but it did not work
rsAppliedPayment.Find "PaymentID = " & TempPaymentId & " AND Invoice = " & rs!INVOICE, , adSearchForward
0
Comment
Question by:mp_lynch
3 Comments
 
LVL 2

Expert Comment

by:hotbudare
Comment Utility
The second sintax is the right one, the problem might be that one of the fields type is a string or a date. If that's the case you should enclose them properly.
I always prefer to use the BuildCriteria() function, as in:

    strCriteria = "(" & BuildCriteria("[PaymentID]", dbLong, CStr(TempPaymentId))
    strCriteria = strCriteria & ") AND ("
    strCriteria = strCriteria & BuildCriteria("[Invoice]", dbLong, CStr(Nz(TempPaymentId, "")))
    strCriteria = strCriteria & ")"
    rsAppliedPayment.Find strCriteria, , adSearchForward

HTH/EQTA
T.S.U. Mario Osorio
Punto Fijo, Falcon, Venezuela
0
 
LVL 11

Accepted Solution

by:
joekendall earned 25 total points
Comment Utility
I created a command button on a form (cmdFind). I then had it open a recordset. Then, you can clone this recordset and filter the cloned recordset to a criteria string. Finally, you can bookmark your first recordset and close the cloned recordset. It then gives a message box with confirmation that it found the record.

You just need to change the names of the Recordset, Fields, Database, etc. to your names for the objects.

Thanks!

Joe


Private Sub cmdFind_Click()
    Dim cn As ADODB.Connection
    Dim rs As ADODB.Recordset
    Dim sCriteria As String
   
    On Error GoTo ErrHandler
   
    Set cn = New ADODB.Connection
    Set rs = New ADODB.Recordset
   
    cn.Open "Driver={Microsoft Access Driver (*.mdb)};DBQ=C:\mydocu~1\code.mdb"
    rs.CursorLocation = adUseClient
    rs.Open "tblReports", cn, adOpenDynamic, adLockOptimistic
   
    sCriteria = "[Report] = '" & txtReport & "' AND [User] = '" & txtUser & "'"
   
    Call MultiFind(rs, sCriteria)
    MsgBox rs.Fields("Report") & " " & rs.Fields("User")
   
    rs.Close
    cn.Close
   
ExitErrHandler:
    Set rs = Nothing
    Set cn = Nothing
   
    Exit Sub
   
ErrHandler:
    With Err
        MsgBox .Number & vbCrLf & .Description & vbCrLf & .Source
    End With
    Resume ExitErrHandler
   
End Sub

Private Sub MultiFind(ByRef oRS As ADODB.Recordset, sCriteria As String)
    Dim rsClone As ADODB.Recordset
   
    On Error GoTo ErrHandler
   
    Set rsClone = oRS.Clone
    rsClone.Filter = sCriteria
    If rsClone.EOF Or rsClone.BOF Then
        oRS.MoveLast
        oRS.MoveNext
    Else
        oRS.Bookmark = rsClone.Bookmark
    End If
   
    rsClone.Close
   
ExitErrHandler:
    Set rsClone = Nothing
   
    Exit Sub
   
ErrHandler:
    With Err
        MsgBox .Number & vbCrLf & .Description & vbCrLf & .Source
    End With
    Resume ExitErrHandler
   
End Sub
0
 

Author Comment

by:mp_lynch
Comment Utility
Perfect thanks alot man.
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Combobox issue 4 25
How calculate median 5 37
Access MDB/PDF 21 28
How add a field with sequential numbers to a form 7 16
Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now