Results 1 to 5 of 5
  1. #1
    testing2Three is offline Novice
    Windows 7 64bit Access 2003
    Join Date
    Nov 2014
    Posts
    2

    Pass parameter to a VBA Module

    I have this code converted from a macro:
    Option Compare DatabaseOption Explicit


    '------------------------------------------------------------
    ' Run_Risk_Assessment_Report1
    '
    '------------------------------------------------------------
    Function Run_Risk_Assessment_Report1()
    On Error GoTo Run_Risk_Assessment_Report1_Err


    DoCmd.SetWarnings False
    ' Clear out the Master Report Table
    DoCmd.OpenQuery "Clear out the Master Report Table", acViewNormal, acEdit
    ' Run the query to make / update the Main Report Table
    DoCmd.OpenQuery "A) Rpt Qry - Select Data Master", acViewNormal, acEdit
    ' update the grand totals
    DoCmd.OpenQuery "Update Grand Total", acViewNormal, acEdit


    ' update the percentages in the Main Report Table
    DoCmd.OpenQuery "Update Percentages in Report Master Report Table", acViewNormal, acEdit
    ' Runs the report
    DoCmd.OpenReport "Risk Assessment Summary", acViewNormal, "", "", acNormal




    Run_Risk_Assessment_Report1_Exit:
    Exit Function


    Run_Risk_Assessment_Report1_Err:
    MsgBox Error$
    Resume Run_Risk_Assessment_Report1_Exit


    End Function
    I need to pass parameter "SAFP" and dates "10/31/2014" to this query "A) Rpt Qry - Select Data Master"

    So I added this code after "DoCmd.OpenQuery "Clear out the Master Report Table", acViewNormal, acEdit" and commented out this line "'DoCmd.OpenQuery "A) Rpt Qry - Select Data Master", acViewNormal, acEdit" so that my query will take the parameters SAFP and 10/31/2014:

    Dim dbs As DAO.Database
    Dim qdf As DAO.QueryDef


    Set dbs = CurrentDb
    'from below original code
    Set qdf = dbs.QueryDefs("A) Rpt Qry - Select Data Master")
    'qdf.Execute

    MsgBox ("database 2")

    qdf.Parameters("[Enter Portfolio Name:]").Value = "SAFP"
    MsgBox ("it worked")
    qdf.Parameters("[Enter as of date:]").Value = "#10/31/2014#"
    MsgBox ("before execute")
    qdf.Execute
    When I try to execute, I get this error message:
    "Data Type mismatch in expression"

    Looks like qdf statements are not working with the rest of the code. Any help will be appreciated.

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    So you're passing parameters to the query, not the function? I don't think you want quotes around the date:

    qdf.Parameters("[Enter as of date:]").Value = #10/31/2014#
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    testing2Three is offline Novice
    Windows 7 64bit Access 2003
    Join Date
    Nov 2014
    Posts
    2
    The qdf function doesn't work if I remove the quotes

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Can you post the db here? I've never used hard coded parameters like that; I get user input from forms.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    NTC is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    Nov 2009
    Posts
    2,392
    put "SAFP" and dates "10/31/2014" in text boxes in an open form; ultimately these controls can be not visible if you prefer

    then call these values in the normal query design

    it is much easier to trouble shoot rather than attempt to stuff them in via code as you are attempting....

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

Similar Threads

  1. Passing a control as a parameter to a code module.
    By MatthewGrace in forum Programming
    Replies: 4
    Last Post: 06-20-2014, 11:14 PM
  2. Replies: 3
    Last Post: 06-10-2014, 05:09 PM
  3. Replies: 2
    Last Post: 02-10-2011, 10:44 AM
  4. Replies: 7
    Last Post: 12-29-2010, 04:07 PM
  5. How to pass what was clicked to module?
    By nichojo in forum Modules
    Replies: 11
    Last Post: 07-22-2010, 08:27 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