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!
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
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
 
Upvote 0

Forum statistics

Threads
1,213,533
Messages
6,114,179
Members
448,554
Latest member
Gleisner2

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