creating and running a SQL statement in VB

casey

Registered User.
Local time
Today, 12:16
Joined
Dec 5, 2000
Messages
448
I'm unfamiliar with the process of creating and running SQL statements through VB code. Can anyone tell me the proper way to do this? Trying to figure this out on my own has my head spinning.
 
Write the SQL code as you normally would. Assign the SQL statement to a string variable, and use this variable when needed.

eg: strSQL="SELECT * FROM Table WHERE [Field] = Criteria ;"

If you want to use variables in criteria, use string concatenation.

Dim strVariable as String
Dim lngVariable as long

strSQL="SELECT * FROM Table WHERE [Field] = """ & strVariable & """ And [Field2] = " & lngVariable & ";"

Hope this is what you were looking for.

Duane Barker
 
Question:
Can this method be used to run action queries that update or insert information into my tables or do I have to use another method?
 
In continuation to BarkerD's response, just in case you didn't know how to run the SQL you must type

DoCmd.RunSQL strSQL

To your second question, you can run any
-VALID- SQL statement, including Update and Make Tables etc...

tc3of4
 
Thanks for the help. That really makes it a lot easier for me.
 

Users who are viewing this thread

Back
Top Bottom