Results 1 to 3 of 3
  1. #1
    Join Date
    Jul 2018
    Posts
    1

    Macro Error 3061 Expected 5

    Hi Everyone,

    I am trying to make a macro that would open a report created, and print each individual sheet. In addition, every sheet has a PDF file linked to it which is saved in a cloud folder. So in essence, the report will print each page and the pdf linked to it which picks up from a query cell called [QuotPath].

    This is my macro:
    Private Sub PrintProjectDetails_Click()
    '' please note you have to install pdf reader application in your system for this code to work
    Dim rst As DAO.Recordset
    Dim strSQL As String
    Dim mypath As String
    Dim myID As Long
    Dim stDocName As String
    Dim stLinkCriteria As String

    stDocName = "078ProjectDetails" '' // this is the report name
    strSQL = "select * from ProjectDetailQueries10" '' // this is the query name
    Set rst = CurrentDb.OpenRecordset(strSQL)

    rst.MoveFirst
    Do While Not rst.EOF


    mypath = rst![QuotPath]
    stLinkCriteria = "[BudgetID]=" & rst![BudgetID] '' // filter by the budget id column name

    CreateObject("Shell.Application").NameSpace(0).Par seName(mypath).InvokeVerb ("Print") '' // this is to print pdf document
    DoCmd.OpenReport stDocName, acNormal, , stLinkCriteria ' // this is to print report


    rst.MoveNext


    Loop
    rst.Close
    MsgBox ("done !")
    End Sub


    Could you please help??

  2. #2
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,954
    This is a VBA procedure not a macro

    The error normally refers to fields being filtered where no or incorrect delimiters have been used
    However the only filter your code shows is BudgetID
    Is BudgetID a number field or text field?

    Do you have other filters buried elsewhere in the code?
    At which line does the code break and give the expected 5 error 3061
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  3. #3
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    You will get that error if the query in the recordset contains form references. Simplest solution if so is to wrap each in the Eval() function. I'm guessing there are 5 of them.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Error 3061. Too few parameters. Expected 1.
    By Glenn_Suggs in forum Programming
    Replies: 5
    Last Post: 02-03-2015, 12:03 PM
  2. Replies: 3
    Last Post: 04-26-2013, 01:37 PM
  3. Runtime Error 3061 Expected 3
    By kumail123 in forum Programming
    Replies: 1
    Last Post: 03-28-2012, 09:44 AM
  4. 3061 Error. Too few parameters. Expected 1.
    By rghollenbeck in forum Queries
    Replies: 5
    Last Post: 09-28-2011, 12:12 PM
  5. Replies: 1
    Last Post: 05-21-2011, 01:33 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