K
keith.bateup
Hi,
I have set up an access conection to a external database on a sql
server through adp. I am trying to export a filtered subform in ms
access to excel
but I understand the best way to do it is to set up a query and change
the sql of the that query to filter the subform and then export the
query.
The problem is that when I set the db = CurrentDb and try to set a
QueryDef using db it throws an error "Run-time error 91: Object
variable or With Block variable not set.
I am out of ideas, has anyone experianced this problem when connecting
to an external data source.
Code:
Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Set db = CurrentDb
' Get the existing export query, or create it if
' it doesn't exist.
On Error Resume Next
Set qdf = db.QueryDefs("qryDataExport")
If qdf Is Nothing Then
Set qdf = db.CreateQueryDef("qryDataExport")
End If
If qdf Is Nothing Then
MsgBox Err.Description, vbExclamation, "Error " &
Err.Number
Exit Sub
End If
On Error GoTo 0
'Here we have got a reference to the export query.
'Set its SQL property to the query we want to export.
qdf.SQL = sqlOutput ' sqlOutput is the query to filter the
subform.
Set qdf = Nothing ' we're done manipulating it.
DoCmd.OutputTo acOutputQuery, "qryDataExport", acFormatXLS,
"export.xls", True
I have set up an access conection to a external database on a sql
server through adp. I am trying to export a filtered subform in ms
access to excel
but I understand the best way to do it is to set up a query and change
the sql of the that query to filter the subform and then export the
query.
The problem is that when I set the db = CurrentDb and try to set a
QueryDef using db it throws an error "Run-time error 91: Object
variable or With Block variable not set.
I am out of ideas, has anyone experianced this problem when connecting
to an external data source.
Code:
Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Set db = CurrentDb
' Get the existing export query, or create it if
' it doesn't exist.
On Error Resume Next
Set qdf = db.QueryDefs("qryDataExport")
If qdf Is Nothing Then
Set qdf = db.CreateQueryDef("qryDataExport")
End If
If qdf Is Nothing Then
MsgBox Err.Description, vbExclamation, "Error " &
Err.Number
Exit Sub
End If
On Error GoTo 0
'Here we have got a reference to the export query.
'Set its SQL property to the query we want to export.
qdf.SQL = sqlOutput ' sqlOutput is the query to filter the
subform.
Set qdf = Nothing ' we're done manipulating it.
DoCmd.OutputTo acOutputQuery, "qryDataExport", acFormatXLS,
"export.xls", True