Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Too few parameters. expectected 1

Status
Not open for further replies.

primagic

IS-IT--Management
Jul 24, 2008
476
GB
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

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
 
strSQL = "SELECT H.CampaignHistoryID, H.CampaignID, H.OrganisationID, C.CampaignName, C.CampaignType, C.CampaignDate FROM tblCampaigns C INNER JOIN tblCampaignHistory H ON C.CampaignID = H.CampaignID WHERE H.CampaignID=" & Forms!frmMain_expandlg!Subform1.Form!CampaignID


Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top