I am trying to create a button that when clicked will populate an outlook email "To" field based on a query. Part of the query criteria is based on a few combo boxes. If I add the below criteria to the query I get this error when running the code - "Too few parameters. Expected 1." If I do not reference the combo boxes in the query the code runs perfectly, except I am not able to limit who I am sending an email to based on the criteria. I have opened the query by itself to see if maybe I referenced something incorrectly but it works fine.
I am new to working with Access - so I appreciate your patience if this is something very simple.
VBA code:
Dim db As Database
Dim rstEmail As DAO.Recordset
Dim strSQL As String
Dim strAddresses As String
Dim Outlook
Set db = CurrentDb()
If bxContactType = "Principal" Then
strSQL = "SELECT [Principal Email] FROM qry_EmailOut;"
Set rstEmail = db.OpenRecordset(strSQL)
Do While Not rstEmail.EOF
Outlook = Outlook + rstEmail("Principal Email") + ";"
rstEmail.MoveNext
Loop
End If
Query Criteria:
[forms]![Email Lists]![bxState]
You should be able to filter the query in the where clause as follows:
strSQL = "SELECT [Principal Email] FROM qry_EmailOut WHERE <column name> = " & Chr(34) & [forms]![Email Lists]![bxState] & Chr(34)
The following link provide additional information:
General overview:
http://support.microsoft.com/kb/281870
Specific related Q/A:
http://www.access-programmers.co.uk/forums/showthread.php?t=192635
Regards,
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.