Can I use a variable for a table name in an SQL statement using VB

  • Thread starter Thread starter ambushsinger
  • Start date Start date
The answer is Yes. Since you posted no details I can only give you a simple
example.

Dim strSQL as String
Dim tblName as String

strSQL = "SELECT A.Field1, A.Field2" & _
" FROM [" & tblName & "] as A INNER JOIN SomeTable"
" ON A.SomeField = SomeTable.SomeMatchingField"



John Spencer
Access MVP 2002-2005, 2007-2010
The Hilltop Institute
University of Maryland Baltimore County
 
Excellent...it works, Thanks

John Spencer said:
The answer is Yes. Since you posted no details I can only give you a simple
example.

Dim strSQL as String
Dim tblName as String

strSQL = "SELECT A.Field1, A.Field2" & _
" FROM [" & tblName & "] as A INNER JOIN SomeTable"
" ON A.SomeField = SomeTable.SomeMatchingField"



John Spencer
Access MVP 2002-2005, 2007-2010
The Hilltop Institute
University of Maryland Baltimore County
Can I use a variable for a table name in an SQL statement using VBA
.
 
Back
Top