Getting "The error 3061, Too few paramaters. Expected 6"

Well for a start you have not put the create email within the loop, which is the base of your problem from the start, in my view. :(

Walk though your code with F8 and hover or debug.print your variables/fields. MSGBOX is too interactive for this in my view.
No need to test for EOF before sending a message, you have a loop doing that.
Just move next, however until you create a new email within the loop, the rest is moot. :(

I gave you the basics. Start from that and then add your complexity.
Personally I see no need to movelast and move first unless you need to know the exact recordcount?

I would myself not even bother as if no records exist your Do Until rs.EOF will be true and none of the email code will be run.

See if Gina's code is easier to understand.
 
Last edited:
Gasman,
I'll continue to work on this. Unfortunately, I need to leave for several hours. More tonight.
Thank you.
 
Hi, I have a relatively simple vba code but it generates the above code. I believe the problem is on the line that begins: Set rs = CurrendDb.OpenRecordset("Temp Daily Table Query for Form")

What am I doing wrong?

Chuck

Code:
Private Sub SendEmailsX_Click()
On Local Error GoTo SendEmailsX_Error
   
    Dim olApp As Object
    Dim olMail As Object
    Dim rs As DAO.Recordset
    Dim EmailList As String

    Set olApp = CreateObject("Outlook.Application")
    Set olMail = olApp.CreateItem(olMailItem)
    Set rs = CurrentDb.OpenRecordset("Temp Daily Table Query for Form")
       
    Do While Not rs.EOF
     olMail.To = rs!Email
     olMail.Subject = "Your XYZ appointment"
     olMail.BodyFormat = olFormatHTML
     olMail.HTMLBody = "Hi, we're coming to your home."
     olMail.Display
     rs.MoveNext
    Loop
   
    olApp.Quit
   
SendEmailsX_Resume:
    Exit Sub
SendEmailsX_Error:
    MsgBox "Sprinkle, the Error (" & CStr(Err.Number) & ") " & Err.Description, _
        vbExclamation, "Error!"
        Resume SendEmailsX_Resume

End Sub
We usually see the error message when:
1) One of the Columns or Expressions in the source Query refers to a misspelled name of a control or function,
2) When a Query has references to Forms that are not open at execution time.
 
The next MsgBox (2-The record number is 0) always tells me that I'm on record 0. I believe that tells me I'm on the first record. Even after the rs.MoveNext command, MsgBox (5-The record number is), always reports record number 0. That tells me that I'm never going to the next record.
It does not. :(
You never increment lngRecordPosition ? Why do you even have it?
 
Last edited:
Gasman, first, thank you for your continued help! It was very helpful. I finally solved the issue as to why I was only getting one email sent when there were multiple emails that could have been sent. The issue was pilot error on my part, what else, and I just needed to move, "Set olMail = olApp.CreateItem(olMailItem)" into the loop. I previously had it before the loop began and therefore, it only ran once. I learn every day.

Thank you again.
 
We are on post 30 and that was advised in post #14?
 

Users who are viewing this thread

Back
Top Bottom