I have the following code which I am trying to use to retrieve the first record from the recordset that has an email address and to send an email to that record. The recordset is actually a datasheet subform on the form that I am running this code from.
I am getting an error Too few parameters. expected 1. It breaks on
The query does have parameters. Would this be the reason for this error.
I am getting an error Too few parameters. expected 1. It breaks on
Code:
Set rs = CurrentDb.OpenRecordset(strSQL)
The query does have parameters. Would this be the reason for this error.
Code:
Private Sub btnTestPlainEmail_Click()
On Error GoTo btnTestPlainEmail_Click_error
Dim recipient As String
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim strSQL As String
Set db = CurrentDb()
strSQL = "SELECT tblCampaignHistory.CampaignHistoryID, tblCampaignHistory.CampaignID, tblCampaignHistory.OrganisationID, tblCampaigns.CampaignName, tblCampaigns.CampaignType, tblCampaigns.CampaignDate FROM tblCampaigns INNER JOIN tblCampaignHistory ON tblCampaigns.CampaignID = tblCampaignHistory.CampaignID WHERE (((tblCampaignHistory.CampaignID)=[Forms]![frmMain_expandlg]![Subform1].[Form]![CampaignID]))"
Set rs = CurrentDb.OpenRecordset(strSQL)
rs.FindFirst "[Email] IS NOT NULL"
SendMail [rs!Email], Nz(rs![MailMergeEmailSubjectLine], rs![SchoolID]), rs![MailMergeEmailMessage], True, Me![MailMergeEmailFileAttachment], False
rs.Close
btnTestPlainEmail_Click_Exit:
On Error Resume Next
rs.Close
Set rs = Nothing
Exit Sub
btnTestPlainEmail_Click_error:
Select Case Err
Case 2501 'action cancelled
Resume btnTestPlainEmail_Click_Exit
Case Else
MsgBox Err & "-" & Error$, vbCritical + vbOKOnly, "Error in module btnTestPlainEmail_Click"
Resume btnTestPlainEmail_Click_Exit
End Select
End Sub