Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 2016
    Location
    Denver
    Posts
    4

    Problem defining variable for a recordset

    Hello,



    In the following code, I keep getting an error that says "too few parameters. Expected 3". I cannot for the life of me understand why.

    The process:
    On frmAccountingDatabaseInput, the user selects a date and invoice type. The Report, "RptInvoice" is supposed to create, and save to the desktop, a copy for each record in tblAccoutingDatabase that matches the criteria.

    As far as I can tell, parameters have been defined. Can someone PLEASE tell me what is wrong with this code? I feel like I'm taking crazy pills!

    VBA:
    Code:
    Sub Save_Invoices_Meet_Criteria()
    
    
    Dim FileName As String
    Dim FilePath As String
    Dim myStmt As String
    Dim Db As DAO.Database
    Dim myrs As DAO.Recordset
    Dim qdf As DAO.QueryDef
    
    
    Set Db = CurrentDb()
    Set qdf = Db.QueryDefs("qryCreateInvoicesApproved")
    
    
        qdf!approve_param = 1
        qdf!date_param = [Forms]![frmAccountingDatabaseInput]![Combo272]
        qdf!type_param = [Forms]![frmAccountingDatabaseInput]![Combo274]
    
    
        DoCmd.SetParameter "approve_param", """" & Yes & """"
        DoCmd.SetParameter "date_param", """" & [Forms]![frmAccountingDatabaseInput]![Combo272] & """"
        DoCmd.SetParameter "type_param", """" & [Forms]![frmAccountingDatabaseInput]![Combo274] & """"
    
    
    Set myrs = CurrentDb.OpenRecordset("SELECT * from qryCreateInvoicesApproved", 2)
    
    
    Do Until myrs.EOF
    
    
        FileName = Me.reference
        foldername = Format(Now(), "YYYY-MM-DD")
        FilePath = "C:\Users\company\Desktop\Invoicing Database\Save_Test\" & foldername & "\" & FileName & ".pdf"
    
    
        DoCmd.OpenReport "RPTInvoice", acViewPreview
        DoCmd.OutputTo acOutputReport, "RPTInvoice", acFormatPDF, FilePath
    
    
        DoCmd.Close
        myrs.MoveNext
    
    
    Loop
    
    
    myrs.Close
    Set myrs = Nothing
    
    
    End Sub
    SQL:
    Code:
    PARAMETERS [approve_param] Bit, [date_param] DateTime, [type_param] Text ( 255 );
    SELECT DISTINCT [reference]
    FROM tblAccountingDatabase
    WHERE (((tblAccountingDatabase.Invoice_approved)=[approve_param])
    And ((tblAccountingDatabase.invoice_date)=[date_param])
        And ((tblAccountingDatabase.Invoice_Type)=[type_param]));
    To anyone who can answer this - You are my hero.

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    Instead of doing this in code,why can't you just make a query?
    You don't need code to make a query.

    the message wants 3 params, so give it 3.

  3. #3
    Join Date
    Aug 2016
    Location
    Denver
    Posts
    4
    Quote Originally Posted by ranman256 View Post
    Instead of doing this in code,why can't you just make a query?
    You don't need code to make a query.

    the message wants 3 params, so give it 3.
    I've written a query but there is more to it than that (see post).

    I've given it 3 parameters, haven't I? Isn't that the whole point of the PARAMETERS part of the query and the qdf part of the code?

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

Similar Threads

  1. recordset value failing on null variable
    By gangel in forum Modules
    Replies: 4
    Last Post: 08-04-2015, 05:25 AM
  2. Defining Variables, Which Variable Type and When?
    By nick404 in forum Programming
    Replies: 4
    Last Post: 07-07-2015, 01:13 PM
  3. open recordset with variable SQL
    By rivereridanus in forum Queries
    Replies: 4
    Last Post: 07-27-2011, 12:58 PM
  4. Replies: 4
    Last Post: 08-05-2010, 01:26 PM
  5. Replies: 3
    Last Post: 02-16-2010, 10:43 PM

Tags for this Thread

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