Find Record in Access using .FindFirst with Multiple Criteria

dloskot

New Member
Joined
Oct 18, 2015
Messages
43
I have spent several hours trying to debug this code. I have not been able to find the answer anywhere.
I have an Access DataBase I am running Access 2010. I want to search the DB to see if a record with several criteria already exists.
I am able to make it work with a single criteria but as soon as I put in an AND or OR I get one or more errors. In the below code the line with the And in it does not work but if I run either of the two lines below it, it works fine.
I hope you can help me .
Thanks Doug

VBA Code:
With KAH_Record
'The first line DOES NOT work, the next two lines do work.  I would like to be able to do
'about 4 different criteria at one.'
    .FindLast "[Payment Method]= '" & PayMethod & "'" And "[EMail]= '" & EMail & "'"
    .FindLast "[Payment Method]= '" & PayMethod & "'"
    .FindLast "[EMail]= '" & EMail & "'"
    
        
        If .NoMatch = False Then
            MsgBox "Found Match"
            'Get_Record_Request = False
            'Exit Function
        Else
        MsgBox "Not Found"
        End If
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Untested code-I think you have to put them all in the same string.

VBA Code:
With KAH_Record
    ' Use three conditions with AND
    .FindLast "[Payment Method]='" & PayMethod & "' AND [EMail]='" & EMail & "' AND [SomeOtherField]='" & SomeValue & "'"
    
    If .NoMatch = False Then
        MsgBox "Found Match"
    Else
        MsgBox "Not Found"
    End If
End With
 
Upvote 0
BigBeach: Thank your line worked. I tried to add the third criteria but it is defined as Currency now I keep getting a Runtime error of '6464' Data type mismatch in criteria expression.
VBA Code:
.FindLast "[Payment Method]='" & PayMethod & "' AND [EMail]='" & EMail & "' AND [Amount Donated]='" & Amount_Donated & "'"

I assume the ' and " are not quite right.
 
Upvote 0
Single or double quotes are text delimiters. Do not use them for numbers or dates. # is for date delimiting only. Try
AND [Amount Donated]=" & Amount_Donated
 
Upvote 0
Micron: Thanks for the explanation about Single, Double quotes and #. I couldn't quite figure them out from all the examples I was looking at.
You suggested change worked. Thanks very much for your your help.
Doug
 
Upvote 0
I think you should give BBB the credit. I was going to make the same suggestion as your solution but I was only a close second.
Glad to have helped either way. :)
 
Upvote 0
Ok one more issue. I added my final Critera which is a date and I keep getting Run-Time Error '13' Type Mismatch.

VBA Code:
.FindLast "[Payment Method]='" & PayMethod & "' AND [EMail]='" & EMail _
     & "' AND [Amount Donated]=" & Amount_Donated And "[Event Date]= #" & Evnet_Date & "#"
 
Upvote 0
BBB: I just caught this myself. I must have looked at that 20 times before posting. Again thank for your help. This board is fantastic.
 
Upvote 0
Well That didn't fix the issue. I am still getting a Run- Time Error "13 Type Mismatch for the first line in the below code but for the second line it works fine.

VBA Code:
.FindLast "[Payment Method]='" & PayMethod & "' AND [EMail]='" & EMail _
     & "' AND [Amount Donated]=" & Amount_Donated And "[Event Date]= #" & Event_Date & "#"
    
     .FindLast "[Event Date]= #" & Event_Date & "#"
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,157
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top