hi VB people,
I need to cycle thru dozens of tables and get the record count for each table.
It is easy to do if I hard-code the table name in the Select statment.
But I really want to just assign the table name to a string variable, and let the Select stmt use the variable as the table name.
Thanks, John
Dim strSQL As String
Dim strTable As String
strTable = "Regions"
Set GMcn = New ADODB.Connection
Set GMrs = New ADODB.Recordset
GMcn.ConnectionString = "Provider=sqloledb;Data Source=GM;Initial Catalog=gm;Integrated Security=SSPI;"
strSQL = "Select Count(*) As Recs From &strTable&"
GMcn.Open
'** get syntax error when opening the recordset **
'** (This stmt is a bit unconventional, but it does work
'** when the table name is hard-coded in strSQL)
Call GMrs.Open(strSQL, GMcn, adOpenForwardOnly, adLockReadOnly, adCmdText)
I need to cycle thru dozens of tables and get the record count for each table.
It is easy to do if I hard-code the table name in the Select statment.
But I really want to just assign the table name to a string variable, and let the Select stmt use the variable as the table name.
Thanks, John
Dim strSQL As String
Dim strTable As String
strTable = "Regions"
Set GMcn = New ADODB.Connection
Set GMrs = New ADODB.Recordset
GMcn.ConnectionString = "Provider=sqloledb;Data Source=GM;Initial Catalog=gm;Integrated Security=SSPI;"
strSQL = "Select Count(*) As Recs From &strTable&"
GMcn.Open
'** get syntax error when opening the recordset **
'** (This stmt is a bit unconventional, but it does work
'** when the table name is hard-coded in strSQL)
Call GMrs.Open(strSQL, GMcn, adOpenForwardOnly, adLockReadOnly, adCmdText)