Results 1 to 4 of 4
  1. #1
    drizzo is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    Jan 2011
    Posts
    4

    Passing Parameters to Queries for Report Generation

    I'm trying to create a subroutine that will run a report for me, and also pass the report a date range in which to use. Using the qdf.Parameter option I am able to set the values of the date parameters in the queries, but when I try and export the report it prompts me to enter the parameters. Below is the code I have come up with thus far.



    Code:
     
    Sub testSub()
    Dim db As DAO.Database
    Dim qdf As DAO.QueryDef
    Dim rst As DAO.Recordset
     
    Set db = CurrentDb
    Set qdf = db.QueryDefs("qry_EMP_GROUP_CURRENT")
    qdf.Parameters("startDate") = "2/1/2011"
    qdf.Parameters("endDate") = "2/17/2011"
    qdf.Parameters("empAssignmentDate") = "2/17/2011"
    Set rst = qdf.OpenRecordset
    DoCmd.OpenReport "Tech Support Summary Report"
    End Sub

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,725

  3. #3
    drizzo is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    Jan 2011
    Posts
    4
    Thanks for the info Orange. I read the articles you linked to, and I used that as a starter. Below is what I came up with. I can then call this sub from VBScript which then I can schedule to run daily.

    Code:
     
    Sub exportReport()
    Dim currentDate As String
    Dim stringVar1 As String
     
    currentDate = Format(Date, "yyyymmdd")
    stringVar1 = "\\sfnt\adduser\Supervisors\TS\Reports\Tech Support Summary Report " & currentDate & ".pdf"
     
    DoCmd.OpenForm "dateSelect"
    Forms!dateSelect!txtStartDate.Value = #1/1/2011#
    Forms!dateSelect!txtEndDate.Value = Date - 1
    Forms!dateSelect!txtEmpAssignmentDate.Value = Forms!dateSelect!txtEndDate.Value
    DoCmd.SetWarnings False
    DoCmd.OutputTo acOutputReport, "Tech Support Summary Report", "PDFFormat(*.pdf)", stringVar1, False, "", , acExportQualityScreen
    DoCmd.SetWarnings True
    End Sub

  4. #4
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,725
    Glad you got it working!!!

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

Similar Threads

  1. Passing parameters to a query
    By stephenaa5 in forum Queries
    Replies: 3
    Last Post: 09-10-2010, 05:32 PM
  2. Automatic Report Generation - Access VBA
    By initiator in forum Programming
    Replies: 2
    Last Post: 04-19-2010, 05:10 AM
  3. Send parameters to queries
    By Merkava in forum Programming
    Replies: 8
    Last Post: 11-06-2009, 02:31 PM
  4. Passing Parameters to a Data Access Page
    By stevie6410 in forum Access
    Replies: 0
    Last Post: 10-01-2009, 09:14 AM
  5. Passing parameters to a report
    By elmousa68 in forum Access
    Replies: 0
    Last Post: 12-07-2006, 01:38 AM

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