-
Error 3061
Hi , I'm trying to send an individual email to small groups of people based on the results of a query. I think my problem occurs because the query result is based on a filter using the selection in a Combo box on a form. The code I'm using returns the following "Error 3061 : Too few parameters.Expected 1" If I just run the query on its own it works perfectly. Some hunting about leads me to belive that if I create the "Where" clause in sql rather than directly in the query this should work but I'm at a loss here as to how to manage this. The code I'm using is below and a big thanks in advance for any help or suggestions.
Code: Private Sub Command14_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("qryCourseDelegates", dbOpenSnapshot)
With rsEmail
.MoveFirst
Do Until rsEmail.EOF
If IsNull(.Fields(13)) = False Then
sToName = .Fields(20)
sSubject = "Confirmation #: " & .Fields(13)
sMessageBody = "Email Body Text " & vbCrLf & _
"Field A: " & .Fields(2) & vbCrLf & _
"Field B: " & .Fields(3) & vbCrLf & _
"Field C: " & .Fields(7)
DoCmd.SendObject acSendNoObject, , , _
sToName, , , sSubject, sMessageBody, False, False
End If
.MoveNext
Loop
End With
Set MyDb = Nothing
Set rsEmail = Nothing
End Sub
-
Why not try opening the RecordSet as a DynaSet rather than a forward only Snapshot?
-
Hi RuralGuy
and thanks for the response, I have to be honest and say that I'm still feeling my way with this a bit., but I'll give that a go.
I have managed to solve it another way - albeit not quite as 'cleanly' but as always one solution leads you to another problem. By changing the If clause to check a tick box for a positive result it filters as I originally wanted and the emails go correctly. But is there a way of getting it to send the email and then clear the box before moving on to the next record?
Cheers
Sorry, as I read that back I wasn't sure if it was particularly clear. The first section now reads:
With rsEmail
.MoveFirst
Do Until rsEmail.EOF
If (.Fields(19)) = -1 Then
and with this in place it is doing all I want, but is there a of getting it to send the email then reset .Fields(19) to 0 before moving oin to check the next record?
-
Sure! Do it before the .MoveNext but I think a Snapshot is read only. You will also need to invoke .Edit and .Update.
-
Hi RuralGuy, thanks for the pointers, I'll give it a try and see how I get on. At least knowing where to start looking is a great help, cheers.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules