Open a recordset with a parameter from an open form

Alain Day

I'm trying to send emails from Access to Outlook. The record-set is to be base on a table using a parameter (date) on an open form.

I get this running OK :

    Set rstEMail = MyDB.OpenRecordset("Select [Courriel] FROM [N_BR_TEST_TOTAL]where [D examen]=#2016-08-20#", dbOpenSnapshot, dbOpenForwardOnly)

But not this :

    Set rstEMail = MyDB.OpenRecordset("Select [Courriel] FROM [N_BR_TEST_TOTAL]where [D examen]=[Forms]![F-EVENEMENT]![DATE]", dbOpenSnapshot, dbOpenForwardOnly)

The second line gives a Run-time error 3061: Too few parameters. Expected 1.

Is there away to pass the value of the date on the Select/Where?

I'd like for an email to be sent to all registered for an event on a specific date shown on the form containing the command button that run the code


tlemaster

You need to remove the form and field reference from the double quotes and join it to the rest of the sql string with an ampersand.

Set rstEMail = MyDB.OpenRecordset("Select [Courriel] FROM [N_BR_TEST_TOTAL]where [D examen]=" & [Forms]![F-EVENEMENT]![DATE], dbOpenSnapshot, dbOpenForwardOnly)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related