variable field name in sql string

  • Thread starter Thread starter Guest
  • Start date Start date
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.
 
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
 
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"
 
Back
Top