Results 1 to 5 of 5
  1. #1
    Shanks is offline Novice
    Windows Vista Access 2007
    Join Date
    Sep 2009
    Posts
    3

    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

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Why not try opening the RecordSet as a DynaSet rather than a forward only Snapshot?

  3. #3
    Shanks is offline Novice
    Windows Vista Access 2007
    Join Date
    Sep 2009
    Posts
    3
    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?

  4. #4
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Sure! Do it before the .MoveNext but I think a Snapshot is read only. You will also need to invoke .Edit and .Update.

  5. #5
    Shanks is offline Novice
    Windows Vista Access 2007
    Join Date
    Sep 2009
    Posts
    3
    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.

Please reply to this thread with any new information or opinions.

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