SQL query works in access but when called from Excel

john robinson

New Member
Joined
Sep 7, 2015
Messages
6
I am trying to send an SQL query string from Excel VBA to an access database. I have a standard module for this and it works fine except when I am trying to get this query to run.
sSQL = SELECT SV_CgRefset.Name FROM SV_CgRefset WHERE ((SV_CgRefset.Name) = "CKD_15");

In short this gets to the line once connections are set up and executes fine but returns empty.
Set Rs = .Execute(sSQL)

IF I send this string to the same database it works fine
sSQL = "SELECT sct.cui, sct.term " & _
"FROM sct " & _
"WHERE (((sct.cui)=105000));"

I have excluded all the other fields I want to return to narrow down the issues and it seems to me it may be due to the "_" in the tablename. It doesn't work for the string "CKD" with no "_" either.
Both "CKD" and CKD_15" are valid names in the table and both string work in access.
I actually want to send a list of names. At one point it did return one result from a list of names but I can't get anything to return now. No errors are generated.
Most grateful for any help.
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
Use single quotes around text string, unless that string can have a single quote. Then it is triple double quotes I think. You would have to test.
If CKD etc are names of fields, then you would concatenate the value of that field, in the same way you would a form control/variable.
 
Upvote 0

Forum statistics

Threads
1,223,888
Messages
6,175,208
Members
452,618
Latest member
Tam84

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