Results 1 to 5 of 5
  1. #1
    cykchanaa is offline Novice
    Windows XP Access 2007
    Join Date
    Jul 2015
    Posts
    4

    Run-time error 3061 when trying to email query results that is linked to a form

    I am trying to create a form button that will automatically email each row of a query result to myself. At first the VBA code worked fine with a standard query. However when I use it with a query that contains a reference to a combobox form such as "<=[Forms]![Reminder]![Monthsleft].[Value] And >=0" I get the 3061 run-time error and "Too few parameters. Expected 1." I have included the VBA code below.

    Private Sub Command9_Click()
    Dim MyDb As DAO.Database
    Dim rsEmail As DAO.Recordset
    Dim sToName As String
    Dim sSubject As String
    Dim sMessageBody As String

    Set MyDb = CurrentDb()
    Set rsEmail = MyDb.OpenRecordset("Query2", dbOpenDynaset)

    With rsEmail
    .MoveFirst
    Do Until rsEmail.EOF
    sToName = "CPPKENC"
    sSubject = "Lease Reminder " & .Fields(4) & " in " & .Fields(3) & " will expire on " & .Fields(7)
    sMessageBody = "We note that the lease of your Engineering Office in Hyderabad will expire on " & .Fields(7) & " If you intend to renew the lease, terms and conditions will need to be submitted for ECC for approval (regardless of changes or not in lease rates). If the terms have yet to be confirmed, it is important to begin the negotiation process as soon as possible with a target to provide the ECC submission at least two months prior to the commencement date of the renewed lease. To ensure sufficient time for ECC approval before the contract expiry date, please prepare the ECC paper and obtain necessary endorsements. Submission details can be found here. The ECC submission template and PSD Questionnaire could be found from this link. Please clearly presents the terms & rent of current and new lease for easy reference. Please do not hesitate to contact us should you require any assistance or guidance in respect of the lease renewal negotiations. Regards, Shirley"


    DoCmd.SendObject acSendNoObject, , , _


    sToName, , , sSubject, sMessageBody, False, False

    .MoveNext
    Loop
    End With

    Set MyDb = Nothing
    Set rsEmail = Nothing
    End Sub

  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
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    cykchanaa is offline Novice
    Windows XP Access 2007
    Join Date
    Jul 2015
    Posts
    4
    Thanks for sending me the link, I think it explains what my problem is. However I don't know how to modify the code as I am new to VBA and copied this code from another forum post.

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Another alternative is to not use a dynamic parameterized query object (I don't). Construct the SQL statement in VBA. Something like:

    Set rsEmail = MyDb.OpenRecordset("SELECT * FROM table/query WHERE fieldname BETWEEN 0 AND " & Me.Monthsleft, dbOpenDynaset)
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Quote Originally Posted by cykchanaa View Post
    Thanks for sending me the link, I think it explains what my problem is. However I don't know how to modify the code as I am new to VBA and copied this code from another forum post.
    Here's the relevant bit from one of my apps (strQuery is a variable containing the name of a query):

    Code:
      Set qdfStatement = db.QueryDefs(strQuery)
      qdfStatement![Forms!frmMainMenu!txtDate] = Forms![frmMainMenu]![txtDate]
      qdfStatement![Forms!frmMainMenu!txtEndDate] = Forms![frmMainMenu]![txtEndDate]
    
    
      Set rs = qdfStatement.OpenRecordset
    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. Run-time error '3061'
    By TheLazyEngineer in forum Programming
    Replies: 1
    Last Post: 03-04-2015, 11:17 AM
  2. Run time error 3061
    By beaurou in forum Modules
    Replies: 18
    Last Post: 02-23-2015, 11:54 AM
  3. Run-Time Error 3061
    By GraeagleBill in forum Programming
    Replies: 2
    Last Post: 09-23-2013, 06:46 AM
  4. Run-time error 3061
    By boywonder in forum Programming
    Replies: 1
    Last Post: 07-20-2011, 06:14 AM
  5. Run-Time error 3061
    By boywonder in forum Programming
    Replies: 12
    Last Post: 05-24-2011, 10:15 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