Page 1 of 3 123 LastLast
Results 1 to 15 of 36
  1. #1
    Gina Maylone is offline Always learning
    Windows 7 64bit Access 2013
    Join Date
    Jun 2013
    Location
    Afton, MN
    Posts
    544

    Runtime Error 3061. Too few parameters, expected 2

    Hello all,



    I have a form (EmailEmployees) that I use to send an email to employees with their upcoming work schedule. It works fine until I add date criteria to the underlying query (using the Form fields "From" and "To") That's when I get the runtime error, too few parameters. If I enter the criteria directly into the underlying query it also works fine. I am stumped! I've been reading threads, double checked my spelling and what not. Any insight will be greatly appreciated!

    Code:
    Private Sub cmdemail_Click()
     Dim Db As DAO.Database
      Dim qDef As DAO.QueryDef
      Dim rsEmail As DAO.Recordset
      
      Dim strEmail As String
      Dim strSubject As String
      Dim strContactName As String
      
      Set Db = CurrentDb
      Set qDef = Db.QueryDefs("EmployeeEmailQuery")
      
      Set rsEmail = qDef.OpenRecordset
      
      Do While Not rsEmail.EOF
        strEmail = rsEmail.Fields("emailaddress").Value
    
       ' 'strContactName = rsEmail.Fields("LastName").Value
    
        DoCmd.SendObject acSendReport, "schedule", formatpdf, strEmail, , ("" & Me!Subject), ("" & Me!Greeting), ("" & Me!Message)
         
           ' False
          
        rsEmail.MoveNext
    
      Loop
       
      Set rsEmail = Nothing
      Set qDef = Nothing
      Set Db = Nothing
       
      MsgBox "Emails have been sent"
    
    End Sub

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2013
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    How about showing us the SQL for the underlying query where you are trying to limit the dates?

  3. #3
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,725

  4. #4
    NTC is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    Nov 2009
    Posts
    2,392
    does your query result have no records? or perhaps is resulting in records that have nulls in critical fields? ... I believe that is your issue.

  5. #5
    Dal Jeanis is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2013
    Location
    Dallas TX
    Posts
    1,742
    Generally, that kind of message happens when you either have a syntax error, or when you have a parameter that is NULL.

    Per these pages:
    http://msdn.microsoft.com/en-us/libr.../ff197046.aspx
    http://www.fmsinc.com/MicrosoftAcces...endObject.html
    This is the format:
    Code:
    DoCmd.SendObject ObjectType, ObjectName, OutputFormat, To, Cc, Bcc, Subject, MessageText, EditMessage, TemplateFile
    So it looks like you may have a missing comma for the BCC parameter:
    Code:
     DoCmd.SendObject acSendReport, "schedule", formatpdf, strEmail, , , ("" & Me!Subject), ("" & Me!Greeting), ("" & Me!Message)
    Also, in this case, I'm not sure what effect the parenthesis around your Subject, Greeting and Message parameters would cause.

    Try these two and see if one of them works:
    Code:
    DoCmd.SendObject acSendReport, "schedule", formatpdf, strEmail, , , "" & Me!Subject, "" & Me!Greeting, "" & Me!Message
    
    DoCmd.SendObject acSendReport, "schedule", formatpdf, strEmail, , , """" & Me!Subject & """", """" & Me!Greeting & """", """" & Me!Message  & """"

  6. #6
    Gina Maylone is offline Always learning
    Windows 7 64bit Access 2013
    Join Date
    Jun 2013
    Location
    Afton, MN
    Posts
    544
    Quote Originally Posted by RuralGuy View Post
    How about showing us the SQL for the underlying query where you are trying to limit the dates?

    Code:
    SELECT MoversScheduleQuery.EmailAddress, MoversScheduleQuery.FullName, MoversScheduleQuery.[Move Date]
    FROM MoversScheduleQuery
    WHERE (((MoversScheduleQuery.[Move Date]) Between [Forms]![EmailEmployees]![from] And [Forms]![EmailEmployees]![to]));
    Thank you.

  7. #7
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2013
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Nothing jumps out at me other than [TO] and [FROM] are reserved words: http://www.allenbrowne.com/AppIssueBadWord.html which can confuse Access on occasion. I also tend to use the dot "." rather than the bang "!".
    [Forms].[EmailEmployees].[from] And [Forms].[EmailEmployees].[to]

  8. #8
    Gina Maylone is offline Always learning
    Windows 7 64bit Access 2013
    Join Date
    Jun 2013
    Location
    Afton, MN
    Posts
    544
    Thank you all for your responses. I tried the various suggestions - have no null fields - and yet still get the Too Few Parameters expected 2 error.

    It errors at this line: Set rsEmail = qDef.OpenRecordset

  9. #9
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,725
    Suggest you post a copy of your database(remove anything private/confidential first). Then zip it.

  10. #10
    Gina Maylone is offline Always learning
    Windows 7 64bit Access 2013
    Join Date
    Jun 2013
    Location
    Afton, MN
    Posts
    544
    Sorry - it won't let me save it backwards - too many functions etc.

  11. #11
    Gina Maylone is offline Always learning
    Windows 7 64bit Access 2013
    Join Date
    Jun 2013
    Location
    Afton, MN
    Posts
    544

    I'll attach it anyway, sans data

    CleanMatts.zip

    I hope I did this correctly.

  12. #12
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,725
    Without some data, it's had to replicate a situation.
    I looked at your Form and have no idea what is expected of me.
    I tied entering 2 dates and preview?????

    Perhaps you could tell the reader what steps should be taken to repeat your problem.

  13. #13
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2013
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    If it helps, I cobbled together enough of the db to demonstrate the issue. I've not resolved it yet but this db demonstrates the problem. There are many issues with this db and this is only one of them. I was working in ac2010 and the db is in ac2007 but I don't think it matters. I could be wrong there.
    Attached Files Attached Files

  14. #14
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2013
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    I wonder if it could have something to do with the fact that SharePoint is involved somehow?

  15. #15
    Gina Maylone is offline Always learning
    Windows 7 64bit Access 2013
    Join Date
    Jun 2013
    Location
    Afton, MN
    Posts
    544
    Quote Originally Posted by RuralGuy View Post
    If it helps, I cobbled together enough of the db to demonstrate the issue. I've not resolved it yet but this db demonstrates the problem. There are many issues with this db and this is only one of them. I was working in ac2010 and the db is in ac2007 but I don't think it matters. I could be wrong there.
    I didn't create this database, I've been brought in to fix it.

    Thank you for your time and suggestioins!

Page 1 of 3 123 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Error 3061 - Too Few parameters
    By DetrieZ in forum Programming
    Replies: 2
    Last Post: 07-09-2013, 12:52 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

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