|
[求助]在点击导出为excel文件时,为什么提示:对象变量或With块变量未设置
Private Sub cmd导出_Click()
On Error GoTo Err_cmd导出_Click
Dim qdf As DAO.QueryDef
Dim strWhere As String
Dim strSQL As String
strWhere = Me.水电费查询子窗体.Form.Filter
If strWhere = "" Then
'没有条件
strSQL = "SELECT * FROM [水电费查询]"
Else
'有条件
strSQL = "SELECT * FROM [水电费查询] WHERE " & strWhere
End If
Set qdf = CurrentDb.QueryDefs("查询结果")
qdf.SQL = strSQL
qdf.Close
Set qdf = Nothing
DoCmd.OutputTo acOutputQuery, "查询结果", acFormatXLS, , True
Exit_cmd导出_Click:
Exit Sub
Err_cmd导出_Click:
MsgBox Err.Description
Resume Exit_cmd导出_Click
End Sub
|
|