I'm trying to connect to the default DB in DAO so i cna create a temp query and do the following simple action:
-------------
Function SQLToExcel(sqlString As String)
Dim cnn As DAO.Connection
Dim qdf As DAO.QueryDef
Set cnn = CurrentDb
Set qdf = cnn.CreateQueryDef(Null, sqlString)
DoCmd.OutputTo acOutputQuery, qdf.Name, acFormatXLS, , True
Set qdf = Nothing
Set cnn = Nothing
End Function
-----------------
The above code gives error 91 object variable or with block variable not set on the line that starts "Set qdf = cnn.CreateQueryDef...". WHat am I doing wrong? I've tried this so many other ways, I've run out of steam on it.
ANy help is appreciated. Thanks!
-------------
Function SQLToExcel(sqlString As String)
Dim cnn As DAO.Connection
Dim qdf As DAO.QueryDef
Set cnn = CurrentDb
Set qdf = cnn.CreateQueryDef(Null, sqlString)
DoCmd.OutputTo acOutputQuery, qdf.Name, acFormatXLS, , True
Set qdf = Nothing
Set cnn = Nothing
End Function
-----------------
The above code gives error 91 object variable or with block variable not set on the line that starts "Set qdf = cnn.CreateQueryDef...". WHat am I doing wrong? I've tried this so many other ways, I've run out of steam on it.
ANy help is appreciated. Thanks!