Link to home
Start Free TrialLog in
Avatar of wilnah
wilnah

asked on

Passing varaible into SQL statement

I want to pass in a variable to replace the field name of a table.  I need the correct syntax.  i.e.

Dim strsql As String, strdte As String
strdte = "9/24"
strsql = "SELECT tblenviroment.Enviroment, tblenviroment.(strsql) FROM tblenviroment WHERE (((tblenviroment.(strsql)) Is Not Null));"
Me.RecordSource = strsql


I need help with the - - tblenviroment.(strsql) syntax.  
I tried tblenviroment. & [strsql] & - - among others with no luck.
ASKER CERTIFIED SOLUTION
Avatar of cjswimmer
cjswimmer

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of nguyenn
nguyenn

Try this:

strsql = "SELECT tblenviroment.Enviroment, tblenviroment.[" & strsql & "]" & " FROM tblenviroment WHERE (tblenviroment.[" & strsql & "]" & "
Is Not Null);"