variable field name in sql string

G

Guest

I am building the following sql string behind a form:

g_strsql = "SELECT TblCurrentTitle.band62 INTO hold "
g_strsql = g_strsql & "FROM tblCurrentTitle "
g_strsql = g_strsql & "WHERE (((TblCurrentTitle.band62) Is Not Null));"

based on the input from the form I will either be using field band62 or
field band64. I cannot figure out how to set this up to accept a variable in
the sql string.

any help would be appreciated.
 
G

Guest

You cannot refer to the variable directly. Instead, create a function that
gets the value of the variable.

Public Function GetMyID()
GetMyID = MyID 'where MyID is the variable whose value is already set
End Function

Now, refer to the function as GetMyID() instead of the variable MyID in SQL
 
M

Marshall Barton

KSH said:
I am building the following sql string behind a form:

g_strsql = "SELECT TblCurrentTitle.band62 INTO hold "
g_strsql = g_strsql & "FROM tblCurrentTitle "
g_strsql = g_strsql & "WHERE (((TblCurrentTitle.band62) Is Not Null));"

based on the input from the form I will either be using field band62 or
field band64. I cannot figure out how to set this up to accept a variable in
the sql string.


First put the name of the field in a variable (named
strField), then use:

g_strsql = "SELECT " & strField & " INTO hold " _
& "FROM tblCurrentTitle "
& "WHERE " & strField & " Is Not Null"
 

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

Top