SQL Access to Excel WHERE Issue

gmazza76

Well-known Member
Joined
Mar 19, 2011
Messages
767
Office Version
  1. 365
Platform
  1. Windows
Good afternoon,

I have a query that runs in excel pulling data from an access table, but I need to pull data through as long as it doesnt match a criteria.
So if person 1 loads the information it is specific to them, but if say the manager loads the file it does something else based on a cell reference

The code below works if the "Business2" is a simple name, but I need it to pull anything other than the name in Business2
The second line just pulls through the referenced information in Business2 where I need it to pull anything but.
ie line one pulls the specific name, but line 2 I need to pull everything bar the name if that makes sense.

What syntax am I missing to make the code understand the difference?

Code:
works
FROM ObservationTable WHERE ((ObservationTable.Business) = '" & Business2 & "') And ((ObservationTable.[Marking Date]) between " & Chr(35) & date1 & Chr(35) & " AND " & Chr(35) & date2 & Chr(35) & " );"

doesnt work
FROM ObservationTable WHERE ((ObservationTable.Business) <> '" & Business2 & "') And ((ObservationTable.[Marking Date]) between " & Chr(35) & date1 & Chr(35) & " AND " & Chr(35) & date2 & Chr(35) & " );"

thanks in a advance
gavin
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.

Forum statistics

Threads
1,215,359
Messages
6,124,488
Members
449,166
Latest member
hokjock

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