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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Select statement

Status
Not open for further replies.

cschaffer

IS-IT--Management
Aug 21, 2001
196
CA
Hey there...this is what I want...I want to pass a variable into a SQL select statment

example
dim variable = blah blah

strQuery = "SELECT * FROM Disasters WHERE DisasterType = 'variable'"
.......
not that hard.....how would I reference "variable" from within the SQL statement...very basic I know...just learning.....

CS
 
You would reference the variable as you would any other VB object. If the variable is a control on a form for example you'd use the following syntax:

strQuery = "SELECT * FROM Disasters WHERE DisasterType = Forms![FormName]![ControlName]"

or


strQuery = "SELECT * FROM Disasters WHERE DisasterType = " & Forms![FormName]![ControlName]
 
Code:
dim X = "blah blah"

strQuery = "SELECT * FROM Disasters WHERE DisasterType = '" & X & "'"
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top