Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Problem calling a function

Posted on 2004-09-21
10
260 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
Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

 
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
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…

838 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