Hi,
OK, I do not have access to an SQL db on a server so I set up a local System DSN via the ODBC-manager.
Following seems to work OK and I wonder if You have the error in the SQL-statement, i e does the table 'tblData' exist?
Code:
Sub SetRecordSet1()
Dim ws As Workspace
Dim db As Database
Dim rs As Recordset
Dim strConnection As String
Dim strSQL As String
Set ws = DBEngine.Workspaces(0)
strConnection = "ODBC;DSN=LocalServer"
strSQL = "SELECT * FROM Customers"
Set db = ws.OpenDatabase("", False, False, strConnection)
Set rs = db.OpenRecordset(strSQL)
MsgBox rs.RecordCount
ws.Close
End Sub
Kind regards,
Dennis