SQL queries in ADO

yoko

Active Member
Joined
Sep 5, 2006
Messages
349
Hello,

I'm having a few problems querying a database using the ADO object.

I've created a recordset object and when I run the following code it all works fine...

Code:
dbRecordSet.Open "SELECT * FROM Staff_List;", cnt, adOpenStatic, adLockOptimistic

It returns a everything in the table, if I do this...

Code:
dbRecordSet.Open "SELECT Name FROM Staff_List;", cnt, adOpenStatic, adLockOptimistic

I get a table with only the names in it, however if I do this...

Code:
dbRecordSet.Open "SELECT Names, Band FROM Staff_List;", cnt, adOpenStatic, adLockOptimistic

I get a sql syntax error even though from what I've read on the net you this should work.

Can anyone let me know where I've gone wrong?

Cheers!
 

Some videos you may like

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off

yoko

Active Member
Joined
Sep 5, 2006
Messages
349
Because I have fat fingers :oops:

I've discovered if I use an alias it works fine...

Code:
dbRecordSet.Open "SELECT TBA.Name, TBA.Band FROM Staff_List TBA;", cnt, adOpenStatic, adLockOptimistic
 

Watch MrExcel Video

Forum statistics

Threads
1,122,694
Messages
5,597,571
Members
414,156
Latest member
WDMix

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
Top