I am trying to run a Bulk email from my Agents data form with a Criteria By "Department" say just email everyone in the Billing Department. I have this in my Bulk Email form on open. But when I open the Bulk Email for I get "Run-time Error 3061" (Too Few Parameters. Expected 1) Here is my on Open Code:
Private Sub Form_Open(Cancel As Integer)
Dim DB As Database Dim RS As Recordset Dim DepartmentName As String Dim MsgRecordSource As String
DepartmentName = Form_frmAgent.DepText MsgRecordSource = "SELECT * FROM qryAgentContact WHERE Department=" & DepartmentName
Set DB = CurrentDb() Set RS = DB.OpenRecordset(MsgRecordSource, dbOpenSnapshot)
RS.MoveLast TotalEmails = RS.RecordCount
RS.Close Set RS = Nothing Set DB = Nothing
Me.MsgSubject.SetFocus
End Sub
Reply from Alex Hedley:
Is Department a String Field?
MsgRecordSource = "SELECT * FROM qryAgentContact WHERE Department=" & DepartmentName => MsgRecordSource = "SELECT * FROM qryAgentContact WHERE Department='" & DepartmentName & "'"
You'll need to wrap it in quotes so " SELECT * FROM qryAgentContact WHERE Department='Finance' "
Sorry, only students may add comments.
Click here for more
information on how you can set up an account.
If you are a Visitor, go ahead and post your reply as a
new comment, and we'll move it here for you
once it's approved. Be sure to use the same name and email address.