Solved

Problem calling a function

Posted on 2004-09-21
10
261 Views
Last Modified: 2006-11-17
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.
0
Comment
Question by:maianoel
  • 3
  • 3
  • 2
  • +2
10 Comments
 
LVL 39

Expert Comment

by:stevbe
ID: 12115801
Why not just chnage the SQL property instead of deleting and re-creating?

Private Sub ExportResults_Click()
    CurrentDb.QueryDefs("qryExport_results").SQL = Sql
End Sub


Steve
0
 
LVL 12

Expert Comment

by:pique_tech
ID: 12115828
What is your code for ExportResults?  Without that, I'm not sure we can help.
0
 
LVL 18

Expert Comment

by:Data-Man
ID: 12115846
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
0
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 
LVL 12

Expert Comment

by:pdebaets
ID: 12115868
The subroutine might have a problem because the variable "sql" is undefined or empty.

Hope this helps
0
 

Author Comment

by:maianoel
ID: 12115890
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_OVERWRITEPROMPT Or ahtOFN_READONLY)
    If strSaveFileName = "" Then Exit Function
    DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "qryExport_results", strSaveFileName
    MsgBox "Export of File complete."
 
End Function

0
 
LVL 12

Expert Comment

by:pique_tech
ID: 12115919
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?
0
 
LVL 18

Accepted Solution

by:
Data-Man earned 500 total points
ID: 12115931
does the compile work?  can you set a breakpoint in the event procedure and then F8 into the code?

Mike
0
 

Author Comment

by:maianoel
ID: 12115943
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.
0
 
LVL 12

Expert Comment

by:pique_tech
ID: 12115950
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?
0
 
LVL 18

Expert Comment

by:Data-Man
ID: 12116025
put your cursor in the function and press F8....does that work?

Mike
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question