Results 1 to 5 of 5
  1. #1
    smith.jr is offline Novice
    Windows 10 Access 2016
    Join Date
    Jan 2014
    Posts
    9

    Too few parameters. Expected 1.

    I have a form with a field where the user enters a SiteID and there are also two option buttons for the user to select if they want the reports to be previewed or printed. There are several command buttons on the form and each one opens or prints a different report based on what the user needs. I'm trying to add a new command button that will open one report if the site is in Texas or New Mexico and a different report if the site is in Oklahoma. When I run the code, I get an error: Too few parameters. Expected 1. I've checked all the spelling and everything is correct. There is one query that is used by both reports and the query runs and both reports open correctly when run/opened directly.



    Thanks in advance.



    Code:
    Private Sub cmdOverfill_Inspection_Click()
    On Error GoTo Err_cmdOverfill_Inspection_Click
    
    
        Dim stDocName As String
        Dim stDocName1 As String
        Dim RS As DAO.Recordset
    
    
        stDocName = "rptOverfill_Inspection_Template_NMorTX"
        stDocName1 = "rptOverfill_Inspection_Template_OK"
        Set RS = CurrentDb.OpenRecordset("qryOverfill_Inspection_Template")
        
        If ([SiteState] = "TX" Or "NM") And (optPreview_or_Print = 1) Then
               DoCmd.OpenReport stDocName, acPreview
            ElseIf ([SiteState] = "TX" Or "NM") And (optPreview_or_Print = 2) Then
              DoCmd.OpenReport stDocName, acprint
            ElseIf ([SiteState] = "OK") And (optPreview_or_Print = 1) Then
               DoCmd.OpenReport stDocName1, acPreview
            ElseIf ([SiteState] = "OK") And (optPreview_or_Print = 2) Then
              DoCmd.OpenReport stDocName1, acprint
         End If
    
    
    Exit_cmdOverfill_Inspection_Click:
        Exit Sub
    
    
    Err_cmdOverfill_Inspection_Click:
        MsgBox Err.Description
        Resume Exit_cmdOverfill_Inspection_Click
        
    End Sub
    Attached Thumbnails Attached Thumbnails Capture 3.JPG  

  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,518
    Does the query have a parameter? If so, that needs to be resolved. The simplest way is wrapping it in the Eval() function in the query.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    1) why open a recordset that you don't use? Remove that and the issue might go away - unless as Paul states, the query has a parameter and the report is bound to it. You can define parameters in the query property sheet, but you still don't need the recordset based on what I see.

    2) having to add buttons to do more of the same basic thing indicates your design approach is lacking (although that's not a certainty). If you list your reports as a set of table records, you can pick the one you need from a combo. If you create a new report, you add the report record and modify the report opening procedure rather than add a button and code it for every report. In your case, you could code to require a view option be chosen as well as a report. You can also use a reports listbox if you want to be able to select multiple reports.
    Last edited by Micron; 08-03-2019 at 01:09 PM. Reason: clarification
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  4. #4
    smith.jr is offline Novice
    Windows 10 Access 2016
    Join Date
    Jan 2014
    Posts
    9
    Micron,

    I've decided to take your suggestion to create a table for the reports. Currently, I don't have that many reports so using the Command Button wasn't that difficult for me. However, I can see the number growing in the future and the table of reports sounds much easier for adding additional reports. I'll do some research on how to set that up.

    Thanks for your help.

  5. #5
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    You're welcome. Give some thought to what fields (information) that might be useful in such a table. Perhaps one for
    - restricting to a class of users
    - a group field (accounting, sales, production)
    - a sort field so that they are in something other than alphabetical by report name
    - a description field for the report's purpose
    - etc.

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

Similar Threads

  1. Too few parameters. Expected 1.
    By SierraJuliet in forum Programming
    Replies: 17
    Last Post: 02-01-2019, 02:28 PM
  2. Too Few Parameters. Expected 1
    By flamesofdoom in forum Programming
    Replies: 1
    Last Post: 02-15-2013, 02:23 PM
  3. too few parameters; expected 2
    By slimjen in forum Forms
    Replies: 13
    Last Post: 07-26-2012, 02:42 PM
  4. Too few parameters. expected 1.
    By seth1685 in forum Programming
    Replies: 1
    Last Post: 01-11-2012, 08:08 AM
  5. Too few parameters. Expected 2.
    By PPCMIS2009 in forum Access
    Replies: 0
    Last Post: 01-28-2009, 01:02 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