Find database record based on multiple criteria

lpking2005

Board Regular
Joined
Mar 21, 2011
Messages
140
Hi,

Not sure it his is meant to be on the Access message board or Excel.??

Im trying to use vba to find a recordset in an access database based on multiple criteria and then overwrite this record with data that is on an excel sheet.

At the moment i possibly have a problem with the SQL reference to the table.
When the code opens the connection it finds no record.
Code:
strSQL = "SELECT * FROM Records WHERE [Current Date] = '" & curDate & "'" & " And [MFG Vessel] = '" & curVessel & "'" & " And [Batch Number] = '" & curBatch & "'"

I think it may be failing because of too many 'And' clauses but im not sure of a way that i can use a 'WHERE' clause when trying to check a record based on multiple field data?

Any help would be appreciated.

Thank you!
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
It's definitely not too many "And" clauses. You can use hundreds without issue should you so choose.

My instinct would be your issue is with date formatting and automatic date format conversion during the query. That's caused me many headaches over the years...
 
Upvote 0

Forum statistics

Threads
1,216,586
Messages
6,131,571
Members
449,655
Latest member
Anil K Sonawane

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