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

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"

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
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,163,879
Messages
5,834,217
Members
430,264
Latest member
ddeboor

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