Results 1 to 3 of 3
  1. #1
    JJPetersen1 is offline Novice
    Windows 8 Access 2016
    Join Date
    Jan 2020
    Posts
    15

    Coding Problem - Too few parameters

    I'm a novice trying to learn. I'm getting an error running the following code (Too few parameters. Expected 1). Can you tell me what I'm missing? Please.



    On Error GoTo Error_Handler




    Dim db As DAO.Database
    Dim rs As DAO.Recordset
    Dim Source As String
    Dim SQL As String
    Dim MyPath As String
    Dim MyFilename As String


    MyPath = "M:\MPF\SigninPlus\AwardsAndDecs\AFGCM_Rosters "


    Set db = CurrentDb
    SQL = "Select Unit_Desc From qryGoodConduct_RIP Group By Unit_Desc"
    Set rs = db.OpenRecordset(SQL)


    While Not rs.EOF
    MyFilename = "AFGCM Roster_" & rs!Unit_Desc & ".pdf"
    DoCmd.OpenReport "rptGoodConduct_RIP", acViewPreview, , "Unit_Desc = '" & rs!Unit_Desc.Value & "'"
    DoCmd.OutputTo acOutputReport, , acFormatPDF, MyPath & MyFilename, False
    DoCmd.Close acReport, "rptGoodConduct_RIP"
    rs.MoveNext
    Wend


    rs.Close




    Set rs = Nothing
    Set db = Nothing





    Error_Handler_Exit:
    On Error Resume Next
    Exit Sub


    Error_Handler:
    MsgBox Err.Description
    Resume Error_Handler_Exit

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,939
    Your query that you are trying to select from needs parameters? Is the query also source for the report?
    Please post code within code tags, the # icon
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  3. #3
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2013 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,115
    You need to evaluate the parameters in your qryGoodConduct_RIP query (see how to do it here:https://stackoverflow.com/questions/...ecordset-issue) or probably easier is to modify that query and wrap the reference to the form control in the built in Eval() function which should allow you to run the query as you do it now but also use it in VBA to define a recordset.

    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

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

Similar Threads

  1. Problem Coding this IIF statement
    By wcrimi in forum Queries
    Replies: 4
    Last Post: 03-20-2017, 09:33 AM
  2. Coding problem with Exit button
    By NightWalker in forum Programming
    Replies: 11
    Last Post: 06-06-2016, 01:05 PM
  3. Problem with query parameters
    By Radtastic10 in forum Queries
    Replies: 9
    Last Post: 02-09-2016, 10:41 AM
  4. Problem about parameters in query
    By ryantam626 in forum Programming
    Replies: 5
    Last Post: 08-22-2012, 08:06 PM
  5. Coding problem.
    By cheyanne in forum Forms
    Replies: 3
    Last Post: 05-19-2012, 05:57 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