Send email help

G

Guest

I'm trying to create a button in a form that will send a mass email the
user-selected group. I have created a query (qryEmailBoard) that works fine
when I use it with the form open. When I click the button, however, I get an
error message "too few parameters: Expected 2" at the line "Set rst =
db.OpenRecordset("qryEmailBoard")" Here is the code that I am using:

Dim rst As DAO.Recordset
Dim db As DAO.Database
Dim strEmail As String

Set db = CurrentDb()
Set rst = db.OpenRecordset("qryEmailBoard")

With rst
If (Not .BOF) And (Not .EOF) Then
.MoveFirst
strEmail = .Fields("email")
.MoveNext
End If

If (Not .BOF) And (Not .EOF) Then
Do Until .EOF
strEmail = strEmail & ", " & .Fields("email")
.MoveNext
Loop
End If
.Close
End With

If strEmail = "" Then
MsgBox "No email addresses were found for that Board"
Else
DoCmd.SendObject acSendNoObject, , acFormatTXT, strEmail, , ,
"Subject", "Message", True
End If

End Sub

Any help with this would be greatly appreciated
 
D

Douglas J Steele

Does qryEmailBoard use controls on a form as criteria? If so, is that form
open when you're running this code?
 
G

Guest

Yes, it uses a control on the form, but I have it open when I click the
button and get the error message. If I have the form open and simply run the
query (qryEmailBoard), that works normally. I only encounter and error when
the command button is clicked.
 
D

Douglas J Steele

I can never remember where Access is capable of resolving references to
parameters and where it isn't.

You might need to open the query and set the values for its parameters:

Dim rst As DAO.Recordset
Dim db As DAO.Database
Dim qdf As DAO.QueryDef

Set db = CurrentDb()
Set qdf = db.QueryDefs("qryEmailBoard")
qdf.Parameters!Parameter1 = Forms!MyForm!MyControl1
qdf.Parameters!Parameter2 = Forms!MyForm!MyControl2
Set rs = qdf.OpenRecordset

(replace Parameter1, Parameter2, MyForm, MyControl1 and MyControl2 with the
actual names)
 
G

Guest

Thanks for your help on this. For Parameter1 and 2, should those be the
names of the fields in qryEmailBoard that are relying on the controls in the
form for criteria? If so, what should the syntax be? Just the field name?
Of should it be qryEmailBoard.FieldName or something like that?
 
D

Douglas J Steele

Unless you have other places where you use qryEmailBoard, you should rename
the parameters in the query to something like [Parameter1] and [Parameter2],
rather than the Forms!MyForm!MyControl1 and Forms!MyForm!MyControl2 you
currently have.
 
G

Guest

Ok, I think I understand what you're saying. In qryEmailBoard I replaced the
criteria that I had with "SelectedCounty" and "SelectedBoard". When I ran
the resulting code, I got a "Item not found in this collection" error at the
line:

qdf.Parameters!SelectedCounty = [Forms]![Report Menu]![ReportCounty]

Here is the full code as I had it:

Private Sub btnEmailBoard_Click()
Dim rst As DAO.Recordset
Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Dim strEmail As String

Set db = CurrentDb()
Set qdf = db.QueryDefs("qryEmailBoard")
qdf.Parameters!SelectedCounty = [Forms]![Report Menu]![ReportCounty]
qdf.Parameters!SelectedBoard = [Forms]![Report Menu]![ReportBoard]
Set rs = qdf.OpenRecordset

With rst
If (Not .BOF) And (Not .EOF) Then
.MoveFirst
strEmail = .Fields("email")
.MoveNext
End If

If (Not .BOF) And (Not .EOF) Then
Do Until .EOF
strEmail = strEmail & ", " & .Fields("email")
.MoveNext
Loop
End If
.Close
End With

If strEmail = "" Then
MsgBox "No email addresses were found for that Board"
Else
DoCmd.SendObject acSendNoObject, , acFormatTXT, strEmail, , ,
"Subjectt", "Message", True
End If

End Sub

Douglas J Steele said:
Unless you have other places where you use qryEmailBoard, you should rename
the parameters in the query to something like [Parameter1] and [Parameter2],
rather than the Forms!MyForm!MyControl1 and Forms!MyForm!MyControl2 you
currently have.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


tminn said:
Thanks for your help on this. For Parameter1 and 2, should those be the
names of the fields in qryEmailBoard that are relying on the controls in the
form for criteria? If so, what should the syntax be? Just the field name?
Of should it be qryEmailBoard.FieldName or something like that?
 
M

Marcin

tminn said:
I'm trying to create a button in a form that will send a mass email the
user-selected group. I have created a query (qryEmailBoard) that works fine
when I use it with the form open. When I click the button, however, I get an
error message "too few parameters: Expected 2" at the line "Set rst =
db.OpenRecordset("qryEmailBoard")" Here is the code that I am using:

Dim rst As DAO.Recordset
Dim db As DAO.Database
Dim strEmail As String

Set db = CurrentDb()
Set rst = db.OpenRecordset("qryEmailBoard")

With rst
If (Not .BOF) And (Not .EOF) Then
.MoveFirst
strEmail = .Fields("email")
.MoveNext
End If

If (Not .BOF) And (Not .EOF) Then
Do Until .EOF
strEmail = strEmail & ", " & .Fields("email")
.MoveNext
Loop
End If
.Close
End With

If strEmail = "" Then
MsgBox "No email addresses were found for that Board"
Else
DoCmd.SendObject acSendNoObject, , acFormatTXT, strEmail, , ,
"Subject", "Message", True
End If

End Sub

Any help with this would be greatly appreciated

=====================================================
FULL LEGAL SOFTWARE !!!
Games, video, program, image, chat, questbook, catalog site, arts, news,
and...
This site it is full register and legal software !!!
Please download and you must register software !!!

PLEASE REGISTER SOFTWARE:
http://www.webteam.gsi.pl/rejestracja.htm
DOWNLOAD LEGAL SOFTWARE:
http://www.webteam.gsi.pl

Full question and post: http://www.webteam.gsi.pl

Contact and service and advanced technology:
http://www.webteam.gsi.pl/kontakt.htm
FAQ: http://www.webteam.gsi.pl/naj_czesciej_zadawane_pytania.htm

Please add me URL for you all site and search engines and best friends !!!

Me site:
SERWIS WEBNETI: http://www.webneti.gsi.pl
PORTAL WEBTEAM: http://www.webteam.gsi.pl
LANGUAGE: http://www.webneti.cjb.net
==========================================================
 
D

Douglas J Steele

Assuming you typed SelectedCounty the same way in both places, try using
Forms("Report Menu").Controls("ReportCounty") instead of [Forms]![Report
Menu]![ReportCounty]

If that still doesn't work, open qryEmailBoard in SQL View, and paste the
SQL here.


--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


tminn said:
Ok, I think I understand what you're saying. In qryEmailBoard I replaced the
criteria that I had with "SelectedCounty" and "SelectedBoard". When I ran
the resulting code, I got a "Item not found in this collection" error at the
line:

qdf.Parameters!SelectedCounty = [Forms]![Report Menu]![ReportCounty]

Here is the full code as I had it:

Private Sub btnEmailBoard_Click()
Dim rst As DAO.Recordset
Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Dim strEmail As String

Set db = CurrentDb()
Set qdf = db.QueryDefs("qryEmailBoard")
qdf.Parameters!SelectedCounty = [Forms]![Report Menu]![ReportCounty]
qdf.Parameters!SelectedBoard = [Forms]![Report Menu]![ReportBoard]
Set rs = qdf.OpenRecordset

With rst
If (Not .BOF) And (Not .EOF) Then
.MoveFirst
strEmail = .Fields("email")
.MoveNext
End If

If (Not .BOF) And (Not .EOF) Then
Do Until .EOF
strEmail = strEmail & ", " & .Fields("email")
.MoveNext
Loop
End If
.Close
End With

If strEmail = "" Then
MsgBox "No email addresses were found for that Board"
Else
DoCmd.SendObject acSendNoObject, , acFormatTXT, strEmail, , ,
"Subjectt", "Message", True
End If

End Sub

Douglas J Steele said:
Unless you have other places where you use qryEmailBoard, you should rename
the parameters in the query to something like [Parameter1] and [Parameter2],
rather than the Forms!MyForm!MyControl1 and Forms!MyForm!MyControl2 you
currently have.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


tminn said:
Thanks for your help on this. For Parameter1 and 2, should those be the
names of the fields in qryEmailBoard that are relying on the controls
in
the
form for criteria? If so, what should the syntax be? Just the field name?
Of should it be qryEmailBoard.FieldName or something like that?


:

I can never remember where Access is capable of resolving references to
parameters and where it isn't.

You might need to open the query and set the values for its parameters:

Dim rst As DAO.Recordset
Dim db As DAO.Database
Dim qdf As DAO.QueryDef

Set db = CurrentDb()
Set qdf = db.QueryDefs("qryEmailBoard")
qdf.Parameters!Parameter1 = Forms!MyForm!MyControl1
qdf.Parameters!Parameter2 = Forms!MyForm!MyControl2
Set rs = qdf.OpenRecordset

(replace Parameter1, Parameter2, MyForm, MyControl1 and MyControl2
with
the
actual names)

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Yes, it uses a control on the form, but I have it open when I
click
the
button and get the error message. If I have the form open and
simply
run
the
query (qryEmailBoard), that works normally. I only encounter and error
when
the command button is clicked.


:

Does qryEmailBoard use controls on a form as criteria? If so, is that
form
open when you're running this code?

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


I'm trying to create a button in a form that will send a mass email
the
user-selected group. I have created a query (qryEmailBoard) that
works
fine
when I use it with the form open. When I click the button, however, I
get
an
error message "too few parameters: Expected 2" at the line
"Set
rst =
db.OpenRecordset("qryEmailBoard")" Here is the code that I am using:

Dim rst As DAO.Recordset
Dim db As DAO.Database
Dim strEmail As String

Set db = CurrentDb()
Set rst = db.OpenRecordset("qryEmailBoard")

With rst
If (Not .BOF) And (Not .EOF) Then
.MoveFirst
strEmail = .Fields("email")
.MoveNext
End If

If (Not .BOF) And (Not .EOF) Then
Do Until .EOF
strEmail = strEmail & ", " & .Fields("email")
.MoveNext
Loop
End If
.Close
End With

If strEmail = "" Then
MsgBox "No email addresses were found for that Board"
Else
DoCmd.SendObject acSendNoObject, , acFormatTXT,
strEmail,
, ,
"Subject", "Message", True
End If

End Sub

Any help with this would be greatly appreciated
 
G

Guest

I made the change you suggested, but got the same error on the same line as
before. Here is the SQL for qryEmailBoard:

SELECT Main.email, Main.County, Main.Board, Main.County2, Main.Board2
FROM Main
WHERE (((Main.Status)<>"Closed" And (Main.Status)<>"Prospective")) OR
(((Main.Status)<>"Closed" And (Main.Status)<>"Prospective"))
GROUP BY Main.email, Main.County, Main.Board, Main.County2, Main.Board2
HAVING (((Main.County)="SelectedCounty") AND ((Main.Board)="SelectedBoard"))
OR (((Main.County2)="SelectedCounty") AND ((Main.Board2)="SelectedBoard"));

The criteria selected on the Report Menu form are County and Board. A
person can have two County/Board combinations, and if either matches, their
email should show up in this query.


Douglas J Steele said:
Assuming you typed SelectedCounty the same way in both places, try using
Forms("Report Menu").Controls("ReportCounty") instead of [Forms]![Report
Menu]![ReportCounty]

If that still doesn't work, open qryEmailBoard in SQL View, and paste the
SQL here.


--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


tminn said:
Ok, I think I understand what you're saying. In qryEmailBoard I replaced the
criteria that I had with "SelectedCounty" and "SelectedBoard". When I ran
the resulting code, I got a "Item not found in this collection" error at the
line:

qdf.Parameters!SelectedCounty = [Forms]![Report Menu]![ReportCounty]

Here is the full code as I had it:

Private Sub btnEmailBoard_Click()
Dim rst As DAO.Recordset
Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Dim strEmail As String

Set db = CurrentDb()
Set qdf = db.QueryDefs("qryEmailBoard")
qdf.Parameters!SelectedCounty = [Forms]![Report Menu]![ReportCounty]
qdf.Parameters!SelectedBoard = [Forms]![Report Menu]![ReportBoard]
Set rs = qdf.OpenRecordset

With rst
If (Not .BOF) And (Not .EOF) Then
.MoveFirst
strEmail = .Fields("email")
.MoveNext
End If

If (Not .BOF) And (Not .EOF) Then
Do Until .EOF
strEmail = strEmail & ", " & .Fields("email")
.MoveNext
Loop
End If
.Close
End With

If strEmail = "" Then
MsgBox "No email addresses were found for that Board"
Else
DoCmd.SendObject acSendNoObject, , acFormatTXT, strEmail, , ,
"Subjectt", "Message", True
End If

End Sub

Douglas J Steele said:
Unless you have other places where you use qryEmailBoard, you should rename
the parameters in the query to something like [Parameter1] and [Parameter2],
rather than the Forms!MyForm!MyControl1 and Forms!MyForm!MyControl2 you
currently have.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Thanks for your help on this. For Parameter1 and 2, should those be the
names of the fields in qryEmailBoard that are relying on the controls in
the
form for criteria? If so, what should the syntax be? Just the field
name?
Of should it be qryEmailBoard.FieldName or something like that?


:

I can never remember where Access is capable of resolving references to
parameters and where it isn't.

You might need to open the query and set the values for its parameters:

Dim rst As DAO.Recordset
Dim db As DAO.Database
Dim qdf As DAO.QueryDef

Set db = CurrentDb()
Set qdf = db.QueryDefs("qryEmailBoard")
qdf.Parameters!Parameter1 = Forms!MyForm!MyControl1
qdf.Parameters!Parameter2 = Forms!MyForm!MyControl2
Set rs = qdf.OpenRecordset

(replace Parameter1, Parameter2, MyForm, MyControl1 and MyControl2 with
the
actual names)

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Yes, it uses a control on the form, but I have it open when I click
the
button and get the error message. If I have the form open and simply
run
the
query (qryEmailBoard), that works normally. I only encounter and
error
when
the command button is clicked.


:

Does qryEmailBoard use controls on a form as criteria? If so, is
that
form
open when you're running this code?

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


I'm trying to create a button in a form that will send a mass
email
the
user-selected group. I have created a query (qryEmailBoard) that
works
fine
when I use it with the form open. When I click the button,
however, I
get
an
error message "too few parameters: Expected 2" at the line "Set
rst =
db.OpenRecordset("qryEmailBoard")" Here is the code that I am
using:

Dim rst As DAO.Recordset
Dim db As DAO.Database
Dim strEmail As String

Set db = CurrentDb()
Set rst = db.OpenRecordset("qryEmailBoard")

With rst
If (Not .BOF) And (Not .EOF) Then
.MoveFirst
strEmail = .Fields("email")
.MoveNext
End If

If (Not .BOF) And (Not .EOF) Then
Do Until .EOF
strEmail = strEmail & ", " & .Fields("email")
.MoveNext
Loop
End If
.Close
End With

If strEmail = "" Then
MsgBox "No email addresses were found for that Board"
Else
DoCmd.SendObject acSendNoObject, , acFormatTXT, strEmail,
, ,
"Subject", "Message", True
End If

End Sub

Any help with this would be greatly appreciated
 
D

Douglas J Steele

Those should be [SelectedCounty] and [SelectedBoard], not "SelectedCounty"
and "SelectedBoard".

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


tminn said:
I made the change you suggested, but got the same error on the same line as
before. Here is the SQL for qryEmailBoard:

SELECT Main.email, Main.County, Main.Board, Main.County2, Main.Board2
FROM Main
WHERE (((Main.Status)<>"Closed" And (Main.Status)<>"Prospective")) OR
(((Main.Status)<>"Closed" And (Main.Status)<>"Prospective"))
GROUP BY Main.email, Main.County, Main.Board, Main.County2, Main.Board2
HAVING (((Main.County)="SelectedCounty") AND ((Main.Board)="SelectedBoard"))
OR (((Main.County2)="SelectedCounty") AND ((Main.Board2)="SelectedBoard"));

The criteria selected on the Report Menu form are County and Board. A
person can have two County/Board combinations, and if either matches, their
email should show up in this query.


Douglas J Steele said:
Assuming you typed SelectedCounty the same way in both places, try using
Forms("Report Menu").Controls("ReportCounty") instead of [Forms]![Report
Menu]![ReportCounty]

If that still doesn't work, open qryEmailBoard in SQL View, and paste the
SQL here.


--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


tminn said:
Ok, I think I understand what you're saying. In qryEmailBoard I
replaced
the
criteria that I had with "SelectedCounty" and "SelectedBoard". When I ran
the resulting code, I got a "Item not found in this collection" error
at
the
line:

qdf.Parameters!SelectedCounty = [Forms]![Report Menu]![ReportCounty]

Here is the full code as I had it:

Private Sub btnEmailBoard_Click()
Dim rst As DAO.Recordset
Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Dim strEmail As String

Set db = CurrentDb()
Set qdf = db.QueryDefs("qryEmailBoard")
qdf.Parameters!SelectedCounty = [Forms]![Report Menu]![ReportCounty]
qdf.Parameters!SelectedBoard = [Forms]![Report Menu]![ReportBoard]
Set rs = qdf.OpenRecordset

With rst
If (Not .BOF) And (Not .EOF) Then
.MoveFirst
strEmail = .Fields("email")
.MoveNext
End If

If (Not .BOF) And (Not .EOF) Then
Do Until .EOF
strEmail = strEmail & ", " & .Fields("email")
.MoveNext
Loop
End If
.Close
End With

If strEmail = "" Then
MsgBox "No email addresses were found for that Board"
Else
DoCmd.SendObject acSendNoObject, , acFormatTXT, strEmail, , ,
"Subjectt", "Message", True
End If

End Sub

:

Unless you have other places where you use qryEmailBoard, you should rename
the parameters in the query to something like [Parameter1] and [Parameter2],
rather than the Forms!MyForm!MyControl1 and Forms!MyForm!MyControl2 you
currently have.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Thanks for your help on this. For Parameter1 and 2, should those
be
the
names of the fields in qryEmailBoard that are relying on the contr
ols
in
the
form for criteria? If so, what should the syntax be? Just the field
name?
Of should it be qryEmailBoard.FieldName or something like that?


:

I can never remember where Access is capable of resolving
references
to
parameters and where it isn't.

You might need to open the query and set the values for its parameters:

Dim rst As DAO.Recordset
Dim db As DAO.Database
Dim qdf As DAO.QueryDef

Set db = CurrentDb()
Set qdf = db.QueryDefs("qryEmailBoard")
qdf.Parameters!Parameter1 = Forms!MyForm!MyControl1
qdf.Parameters!Parameter2 = Forms!MyForm!MyControl2
Set rs = qdf.OpenRecordset

(replace Parameter1, Parameter2, MyForm, MyControl1 and
MyControl2
with
the
actual names)

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Yes, it uses a control on the form, but I have it open when I click
the
button and get the error message. If I have the form open and simply
run
the
query (qryEmailBoard), that works normally. I only encounter and
error
when
the command button is clicked.


:

Does qryEmailBoard use controls on a form as criteria? If so, is
that
form
open when you're running this code?

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


I'm trying to create a button in a form that will send a mass
email
the
user-selected group. I have created a query
(qryEmailBoard)
that
works
fine
when I use it with the form open. When I click the button,
however, I
get
an
error message "too few parameters: Expected 2" at the line "Set
rst =
db.OpenRecordset("qryEmailBoard")" Here is the code that I am
using:

Dim rst As DAO.Recordset
Dim db As DAO.Database
Dim strEmail As String

Set db = CurrentDb()
Set rst = db.OpenRecordset("qryEmailBoard")

With rst
If (Not .BOF) And (Not .EOF) Then
.MoveFirst
strEmail = .Fields("email")
.MoveNext
End If

If (Not .BOF) And (Not .EOF) Then
Do Until .EOF
strEmail = strEmail & ", " & ..Fields("email")
.MoveNext
Loop
End If
.Close
End With

If strEmail = "" Then
MsgBox "No email addresses were found for that Board"
Else
DoCmd.SendObject acSendNoObject, , acFormatTXT, strEmail,
, ,
"Subject", "Message", True
End If

End Sub

Any help with this would be greatly appreciated
 
G

Guest

That did it! The whole thing is working now. Thank you so much for taking
the time to help me with this!

Douglas J Steele said:
Those should be [SelectedCounty] and [SelectedBoard], not "SelectedCounty"
and "SelectedBoard".

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


tminn said:
I made the change you suggested, but got the same error on the same line as
before. Here is the SQL for qryEmailBoard:

SELECT Main.email, Main.County, Main.Board, Main.County2, Main.Board2
FROM Main
WHERE (((Main.Status)<>"Closed" And (Main.Status)<>"Prospective")) OR
(((Main.Status)<>"Closed" And (Main.Status)<>"Prospective"))
GROUP BY Main.email, Main.County, Main.Board, Main.County2, Main.Board2
HAVING (((Main.County)="SelectedCounty") AND ((Main.Board)="SelectedBoard"))
OR (((Main.County2)="SelectedCounty") AND ((Main.Board2)="SelectedBoard"));

The criteria selected on the Report Menu form are County and Board. A
person can have two County/Board combinations, and if either matches, their
email should show up in this query.


Douglas J Steele said:
Assuming you typed SelectedCounty the same way in both places, try using
Forms("Report Menu").Controls("ReportCounty") instead of [Forms]![Report
Menu]![ReportCounty]

If that still doesn't work, open qryEmailBoard in SQL View, and paste the
SQL here.


--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Ok, I think I understand what you're saying. In qryEmailBoard I replaced
the
criteria that I had with "SelectedCounty" and "SelectedBoard". When I ran
the resulting code, I got a "Item not found in this collection" error at
the
line:

qdf.Parameters!SelectedCounty = [Forms]![Report Menu]![ReportCounty]

Here is the full code as I had it:

Private Sub btnEmailBoard_Click()
Dim rst As DAO.Recordset
Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Dim strEmail As String

Set db = CurrentDb()
Set qdf = db.QueryDefs("qryEmailBoard")
qdf.Parameters!SelectedCounty = [Forms]![Report Menu]![ReportCounty]
qdf.Parameters!SelectedBoard = [Forms]![Report Menu]![ReportBoard]
Set rs = qdf.OpenRecordset

With rst
If (Not .BOF) And (Not .EOF) Then
.MoveFirst
strEmail = .Fields("email")
.MoveNext
End If

If (Not .BOF) And (Not .EOF) Then
Do Until .EOF
strEmail = strEmail & ", " & .Fields("email")
.MoveNext
Loop
End If
.Close
End With

If strEmail = "" Then
MsgBox "No email addresses were found for that Board"
Else
DoCmd.SendObject acSendNoObject, , acFormatTXT, strEmail, , ,
"Subjectt", "Message", True
End If

End Sub

:

Unless you have other places where you use qryEmailBoard, you should
rename
the parameters in the query to something like [Parameter1] and
[Parameter2],
rather than the Forms!MyForm!MyControl1 and Forms!MyForm!MyControl2 you
currently have.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Thanks for your help on this. For Parameter1 and 2, should those be
the
names of the fields in qryEmailBoard that are relying on the contr ols
in
the
form for criteria? If so, what should the syntax be? Just the field
name?
Of should it be qryEmailBoard.FieldName or something like that?


:

I can never remember where Access is capable of resolving references
to
parameters and where it isn't.

You might need to open the query and set the values for its
parameters:

Dim rst As DAO.Recordset
Dim db As DAO.Database
Dim qdf As DAO.QueryDef

Set db = CurrentDb()
Set qdf = db.QueryDefs("qryEmailBoard")
qdf.Parameters!Parameter1 = Forms!MyForm!MyControl1
qdf.Parameters!Parameter2 = Forms!MyForm!MyControl2
Set rs = qdf.OpenRecordset

(replace Parameter1, Parameter2, MyForm, MyControl1 and MyControl2
with
the
actual names)

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Yes, it uses a control on the form, but I have it open when I
click
the
button and get the error message. If I have the form open and
simply
run
the
query (qryEmailBoard), that works normally. I only encounter and
error
when
the command button is clicked.


:

Does qryEmailBoard use controls on a form as criteria? If so, is
that
form
open when you're running this code?

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


I'm trying to create a button in a form that will send a mass
email
the
user-selected group. I have created a query (qryEmailBoard)
that
works
fine
when I use it with the form open. When I click the button,
however, I
get
an
error message "too few parameters: Expected 2" at the line
"Set
rst =
db.OpenRecordset("qryEmailBoard")" Here is the code that I am
using:

Dim rst As DAO.Recordset
Dim db As DAO.Database
Dim strEmail As String

Set db = CurrentDb()
Set rst = db.OpenRecordset("qryEmailBoard")

With rst
If (Not .BOF) And (Not .EOF) Then
.MoveFirst
strEmail = .Fields("email")
.MoveNext
End If

If (Not .BOF) And (Not .EOF) Then
Do Until .EOF
strEmail = strEmail & ", " & ..Fields("email")
.MoveNext
Loop
End If
.Close
End With

If strEmail = "" Then
MsgBox "No email addresses were found for that Board"
Else
DoCmd.SendObject acSendNoObject, , acFormatTXT,
strEmail,
, ,
"Subject", "Message", True
End If

End Sub

Any help with this would be greatly appreciated
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top