maianoel
asked on
Problem calling a function
OK, I am having a problem calling a Function in one of my subroutines:
Private Sub ExportResults_Click()
Dim qdQD As QueryDef
DoCmd.DeleteObject acQuery, "qryExport_results"
Set qdQD = CurrentDb.CreateQueryDef(" qryExport_ results", Sql)
ExportResults CAN'T CALL THIS
End Sub
When I attempt to export the document, I receive an error indicating "Invalid use of property." I am not sure what the problem is. It worked fine in Access 2000, but we just got Access 2003 and it no longer works.
Private Sub ExportResults_Click()
Dim qdQD As QueryDef
DoCmd.DeleteObject acQuery, "qryExport_results"
Set qdQD = CurrentDb.CreateQueryDef("
ExportResults CAN'T CALL THIS
End Sub
When I attempt to export the document, I receive an error indicating "Invalid use of property." I am not sure what the problem is. It worked fine in Access 2000, but we just got Access 2003 and it no longer works.
What is your code for ExportResults? Without that, I'm not sure we can help.
can you debug | Compile?
what about using the Call keyword
Call ExportResults
I try and prefix all my functions with fn and subs with sb to avoid any keyword conflicts. Also is ExportResults a function or a sub?
Mike
what about using the Call keyword
Call ExportResults
I try and prefix all my functions with fn and subs with sb to avoid any keyword conflicts. Also is ExportResults a function or a sub?
Mike
The subroutine might have a problem because the variable "sql" is undefined or empty.
Hope this helps
Hope this helps
ASKER
Sorry. The code for ExportResults is below. Also, I tried Call ExportResults and I still got the same error.
Function ExportResults()
Dim strFilter As String
Dim lngFlags As Long
Dim strInputFileName As String
strFilter = ahtAddFilterItem(strFilter , "Excel Files (*.xls)", "*.xls")
strSaveFileName = ahtCommonFileOpenSave( _
OpenFile:=False, _
Filter:=strFilter, _
Flags:=ahtOFN_OVERWRITEPRO MPT Or ahtOFN_READONLY)
If strSaveFileName = "" Then Exit Function
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "qryExport_results", strSaveFileName
MsgBox "Export of File complete."
End Function
Function ExportResults()
Dim strFilter As String
Dim lngFlags As Long
Dim strInputFileName As String
strFilter = ahtAddFilterItem(strFilter
strSaveFileName = ahtCommonFileOpenSave( _
OpenFile:=False, _
Filter:=strFilter, _
Flags:=ahtOFN_OVERWRITEPRO
If strSaveFileName = "" Then Exit Function
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "qryExport_results", strSaveFileName
MsgBox "Export of File complete."
End Function
Let me ask a clarifying question:
Your code snippet appears to be from a button's On Click event. It appears that you delete and recreate a query then you call a sub, ExportResults. Is it that call to ExportResults that is failing, or is it the button ExportResults_Click event that's failing?
Your code snippet appears to be from a button's On Click event. It appears that you delete and recreate a query then you call a sub, ExportResults. Is it that call to ExportResults that is failing, or is it the button ExportResults_Click event that's failing?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
It appears it just the function call that's failing. Clicking the button appears to create the query correctly, it just runs into some problem when calling the ExportResults function.
If you debug/single-step through the code, is the failure point within this sub or in the button event's attempt to call it?
put your cursor in the function and press F8....does that work?
Mike
Mike
Private Sub ExportResults_Click()
CurrentDb.QueryDefs("qryEx
End Sub
Steve