Getting "The error 3061, Too few paramaters. Expected 6" (1 Viewer)

Pat and Gasman. I apologize for my late reply. I was called away for several hours. I apologize.

Gasman, you said "I just copied a block of code I used to use, so just look at the logic and where I created a new email each time." I don't believe you posted that code here. If you could, that hopefully will help.
 
I think others have already directed you to the right path, the error simply says hay look here your query has some parameter operated by your form declare the parameters:

You declare parameters like below:

Code:
Dim prm As DAO.Parameter
For Each prm In qdf.Parameters
        prm = Eval(prm.Name)
    Next prm

rs.Close
Set qdf = Nothing
Set prm = Nothing
 
Pat and Gasman. I apologize for my late reply. I was called away for several hours. I apologize.

Gasman, you said "I just copied a block of code I used to use, so just look at the logic and where I created a new email each time." I don't believe you posted that code here. If you could, that hopefully will help.
See post #14?

Basically you need
Code:
Create Outlook app object

Do Until EOF
    Create Email
    Populate Email
    Add any attachments
    Send Email
Loop
 
I'm sorry to be a PIA but I'm still fighting this issue. The bottom line is that it never moves to the next record. The record source is a simple table with three records in it. You can see from the code that I have a lot of MsgBox's in it so I can see what's going on. The first MsgBox confirms there are three records and the next MsgBox (1-Am I at the EOF) always produces, False. 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.

Again, I'm confused. The record source is a simple table. Any ideas?
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
    Dim Subj As String
    Dim Bdy As String
    Dim LngCount As Long
    Dim lngRSCount As Long
    Dim lngRecordPosition As Long
    
    Subj = "Your appointment today"
    Bdy = "Hi, we're going to be at your home"

    Set olApp = CreateObject("Outlook.Application")
    Set olMail = olApp.CreateItem(olMailItem)
    Set rs = CurrentDb.OpenRecordset("Temp Daily Table Query for Form Test")
    lngRSCount = rs.RecordCount
    MsgBox ("0-The number of records in the table is: " & lngRSCount)
    If Not rs.EOF Then
     rs.MoveLast ' Move to the last record
     rs.MoveFirst ' Move back to the first record
    End If
    
    While Not rs.EOF
     MsgBox ("1- Am I at the EOF? " & rs.EOF)
     MsgBox ("2-The record number is: " & lngRecordPosition)
     olMail.To = rs!EmailX
     olMail.Subject = Subj & " " & lngRecordPosition
   '  olMail.BodyFormat = olFormatHTML
   '  olMail.HTMLBody = Bdy
     olMail.Body = Bdy
    ' olMail.Display
   '  olMail.Save
     olMail.Send
  '   rs.Edit
  '   rs.Update
  '   rs.Close
     MsgBox ("3-The record number is: " & lngRecordPosition)
     If Not rs.EOF Then
      MsgBox ("4- Am I at the EOF? " & rs.EOF)
      rs.MoveNext
     End If
     MsgBox ("5-The record number is: " & lngRecordPosition)
     Wend
  '  Loop
 '   End If
    olApp.Quit
    
    
SendEmailsX_Resume:
    Exit Sub
SendEmailsX_Error:
    MsgBox "Sprinkle, the Error (" & CStr(Err.Number) & ") " & Err.Description, _
        vbExclamation, "Error!"
        Resume SendEmailsX_Resume
 
End Sub
 
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.
 

Users who are viewing this thread

Top Bottom