Building SQL string

  • Thread starter Thread starter Steve
  • Start date Start date
S

Steve

Could somebody please give me a basic run-through and
example of how to build an SQL string and display said
string in MSG Box.
I am building a QBF form and need some help with the SQL
string. I using Access 2002 DAO.
Thanks for reading and hopefully responding to this plea.
 
Not quite sure what you're looking for. A SQL string is just a statement
that you can assign to a variable, something like:

Dim strSQL As String

strSQL = "SELECT Table1.Field1, "
strSQL = strSQL & "Table2.Field2 "
strSQL = strSQL & "FROM Table1 "
strSQL = strSQL & "INNER JOIN Table2 "
strSQL = strSQL & "ON Table1.Field1 = Table2.Field1 "
strSQL = strSQL & "WHERE Table1.Field1 < 5 "
strSQL = strSQL & "ORDER BY Table2.Field2"

MsgBox "The SQL I'm going to use is " & strSQL

The assignment could also have been done using:

strSQL = "SELECT Table1.Field1, " & _
"Table2.Field2 " & _
"FROM Table1 " & _
"INNER JOIN Table2 " & _
"ON Table1.Field1 = Table2.Field1 " & _
"WHERE Table1.Field1 < 5 " & _
"ORDER BY Table2.Field2"
 
Back
Top