Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL select statement in VB for Access Dbase 1

Status
Not open for further replies.

kah0563

Programmer
Feb 7, 2005
6
US
When using left join in a select statement, the table is referenced and then a period, then the field id. I am trying to create a Select statement in VB using a variable as the table name, and trying to concatenate the variable with ".fieldname". The select statement doesn't like this. Is there a way to code this with extra quotes or something?

For example, typical select statement might read "Select table1.field1, table1.field2, table1.field3 FROM table1"

What I want to do is replace the table1 references within the quotes with a variable name. The table needs to be variable, and I can't just code it like this "Select " & variable & ".field1," & variable & ".field2," & variable & ".field3 FROM " & variable

Codes seems to stumble on the period before field identifiers. Is there another way to code this.

Thanks
 
What's wrong with this ?
"Select " & variable & ".field1," & variable & ".field2," & variable & ".field3 FROM " & variable

If your table name may contain space, try this:
"Select [" & variable & "].field1,[" & variable & "].field2,[" & variable & "].field3 FROM [" & variable & "]"

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Thanks PHV. I didn't have any spaces in the table name, but the brackets seem to conquer the problem anyway. I appreciate the input.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top