Simple i think.... breaking SQL

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

My syntax is slightly wrong and having a look on the help file hasnt helped.

This works--------------------------------------------------------------------
Set rs = db.OpenRecordset("SELECT description FROM" & selectTable)

How do i get this to work?---------------------------------------------------
Dim i As String
i= "description"
I have tried this -> Set rs = db.OpenRecordset("SELECT" i " FROM" &
selectTable)
+ this -> Set rs = db.OpenRecordset("SELECT' i ' FROM" &
selectTable)
+ this -> Set rs = db.OpenRecordset("SELECT" & i " FROM" &
selectTable)

im sure the fix is very simple, thanks in advance
 
Made it simpler to read below:

'This works
Set rs = db.OpenRecordset("SELECT description FROM" & selectTable)

'Trying to get it so that i can put the column name from a variable
Dim i As String
i= "description"

'none of these work
'Set rs = db.OpenRecordset("SELECT" i " FROM" & selectTable)
'Set rs = db.OpenRecordset("SELECT' i ' FROM" & selectTable)
'Set rs = db.OpenRecordset("SELECT" & i " FROM" & selectTable)

im sure the fix is very simple, thanks in advance
 
You need this:

Dim i As String
i = "description"

Set rs = db.OpenRecordset("SELECT " & i & " FROM " & selectTable)

It won't matter, but I wouldn't pick i for the variable name as this is
normally
for an integer or long variable. Pick something like strField or sField.


RBS
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top