I have a form which is used as the basis of a query to choose which people a user wants to e-mail.
Once a user has selected various options on the form (used as the basis of the query) I want them to click a button which makes the first form invisible and opens a new form containing a text box box with all the relevant e-mail addresses in. (I then want a copy button so they can copy all those e-mail addresses and paste into the BCC recipients box of whatever e-mail program they are using)
I have written the below code which I hoped would work but does not. I get an error saying there are "Too few parameters. Expected 8" referring to the "Set EmailsList = Db.OpenRecordset("AddressMailList")" Line. Yet the name of the query referred to ("AddressMailList") is definitely correct and everything I read suggests that the number of parameters is correct.
I would be grateful for any suggestions as to where I am going wrong. Also, I have no idea whether the code lower works as it does not get that far.
Many thanks in advance for any help.
Private Sub Form_Open(Cancel As Integer)
Dim Db As DAO.Database
Dim EmailsList As DAO.Recordset
Set Db = CurrentDb()
' "AddressMailList" is the name of the query I want to loop through
Set EmailsList = Db.OpenRecordset("AddressMailList")
Dim Emails As String
' Now loop through values in the query and add e-mail addresses to the
' string "Emails" separated by semi-colons:
Do While Not EmailsList.EOF
Emails = Emails + EmailsList![EmailAddress]
Emails = Emails + "; "
EmailsList.MoveNext
Loop
' Now enter the string "Emails" into the textbox [EmailList1]
[EmailList1] = Emails
End Sub
Once a user has selected various options on the form (used as the basis of the query) I want them to click a button which makes the first form invisible and opens a new form containing a text box box with all the relevant e-mail addresses in. (I then want a copy button so they can copy all those e-mail addresses and paste into the BCC recipients box of whatever e-mail program they are using)
I have written the below code which I hoped would work but does not. I get an error saying there are "Too few parameters. Expected 8" referring to the "Set EmailsList = Db.OpenRecordset("AddressMailList")" Line. Yet the name of the query referred to ("AddressMailList") is definitely correct and everything I read suggests that the number of parameters is correct.
I would be grateful for any suggestions as to where I am going wrong. Also, I have no idea whether the code lower works as it does not get that far.
Many thanks in advance for any help.
Private Sub Form_Open(Cancel As Integer)
Dim Db As DAO.Database
Dim EmailsList As DAO.Recordset
Set Db = CurrentDb()
' "AddressMailList" is the name of the query I want to loop through
Set EmailsList = Db.OpenRecordset("AddressMailList")
Dim Emails As String
' Now loop through values in the query and add e-mail addresses to the
' string "Emails" separated by semi-colons:
Do While Not EmailsList.EOF
Emails = Emails + EmailsList![EmailAddress]
Emails = Emails + "; "
EmailsList.MoveNext
Loop
' Now enter the string "Emails" into the textbox [EmailList1]
[EmailList1] = Emails
End Sub