Access Query via VBA

mikeymay

Well-known Member
Joined
Jan 17, 2006
Messages
1,632
Office Version
  1. 365
Platform
  1. Windows
I need to return some access records where a field doesn't contain two specific text strings.

I am using the following to build the query
Code:
strQuery = "SELECT InvDate, Agent, BoxRef, Supplier, Invoice FROM SageData WHERE (Supplier Not Like '*CNG*' AND Supplier Not Like '*Swalec*') AND InvDate = #" & Format(Range("Controls_ExcInvDate"), "m/d/yyy") & "#"
This executes but returns nothing and there are records in the table that meet the criteria so I'm assuming the 'Not Like' part isn't correct.

I have tried using a % instead of a * and multiple variants of using parenthesis to no avail......

Could anyone correct this for me?

TIA
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
hello

I'm pretty sure for Excel VBA querying MS Access use % wildcard

I think the problem is the date format with THREE y - m/d/yyy
Likely that should be FOUR, m/d/yyyy

Anytime like this I have a problem I debug.print the SQL & review it in the immediate window. (Or you can look in the locals window.)

If you still have a problem, please debug.print & see if that reveals an issue. If still stuck, post back with the result.

cheers
 
Upvote 0
The issue was the date format....schoolboy error!!

Thanks
 
Upvote 0

Forum statistics

Threads
1,223,889
Messages
6,175,226
Members
452,620
Latest member
dsubash

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