Alain Day
Alain Day

Reputation: 13

Open a recordset with a parameter from an open form

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


Upvotes: 1

Views: 472

Answers (1)

tlemaster
tlemaster

Reputation: 859

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)

Upvotes: 1

Related Questions