Solved

Problem calling a function

Posted on 2004-09-21
10
257 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
 
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

Free Gift Card with Acronis Backup Purchase!

Backup any data in any location: local and remote systems, physical and virtual servers, private and public clouds, Macs and PCs, tablets and mobile devices, & more! For limited time only, buy any Acronis backup products and get a FREE Amazon/Best Buy gift card worth up to $200!

Join & Write a Comment

In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
Today's users almost expect this to happen in all search boxes. After all, if their favourite search engine juggles with tens of thousand keywords while they type, and suggests matching phrases on the fly, why shouldn't they expect the same from you…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

744 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now