Results 1 to 3 of 3
  1. #1
    chris.williams is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2011
    Posts
    94

    Variable Not passing to query

    I have a command button which when clicked, runs a VBA macro which saves a report to a PDF for the current record. The report is based on a predefined filter for based on the current ID field on the original form.



    I have tried setting the criteria field to the current record of the form, setting a variable to the ID field. But the query is not getting the information to compare and the output of the report is all #Type and #Error.

    When the macro is run, the query runs and prompts for the information the criteria is looking for.

    How do I pass a variable from a form to a query in VBA?

    Code:
    Public Sub SaveFormToPDF_Click()
    
    Dim CurrentID
    
    CurrentID = [TaskSR]
    MsgBox (CurrentID)
    
    DoCmd.OutputTo acOutputReport, "rpt_Certificate", acFormatPDF, "..\Desktop\" & [FTSOCertNumber] & ".pdf"
    
    End Sub

  2. #2
    hertfordkc is offline 18 year novice
    Windows XP Access 2007
    Join Date
    Mar 2011
    Posts
    481

    Passing variables

    Missing values for variables are usually the result of flawed syntax. Depending on your version of Access, the variable references range from me.something to Forms.[Formname].[variablename] and sometimes the periods are replaced by exclamation points.
    So...experiment with your variable references.

  3. #3
    chris.williams is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2011
    Posts
    94
    I am using Access 2010 - all syntax has been posted along with the errors. I also inserted a mesbox to see what was in the variable and to see if the form side was working and it displays correctly - but that is from within the form, not the query.

    I am thinking the issue must reside within the query side. I have also posted an image of the syntax in the query.

    Any other or more specific ideas?

Please reply to this thread with any new information or opinions.

Similar Threads

  1. passing a variable to an append query
    By Baroj Von Reich in forum Programming
    Replies: 4
    Last Post: 09-02-2011, 08:08 AM
  2. Passing Form Variable to Query
    By allenrickson in forum Reports
    Replies: 10
    Last Post: 06-27-2011, 07:33 PM
  3. Passing SQL result into variable
    By jonny in forum Access
    Replies: 3
    Last Post: 10-18-2009, 07:46 AM
  4. Passing a variable to a form
    By cjamps in forum Forms
    Replies: 0
    Last Post: 03-02-2009, 05:32 AM
  5. Passing a value from a variable to an update query
    By MUKUDU99 in forum Programming
    Replies: 0
    Last Post: 08-24-2008, 11:14 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums