Change the query being referenced by a function, depending on context
I have a custom function in Access 2007 that hinges on grabbing data out of a specific query. It opens Outlook, creates a new email and populates the fields with specific addresses and data taken from the query ("DecisionEmail")
.
("RequestEmail")
to populate the email with that data. So all I have to do is change this line:
Set MailList = db.OpenRecordset("DecisionEmail")
This is my desired result开发者_StackOverflow中文版: If the user is on Form_Decision
and clicks the button "Send email"
, "DecisionEmail"
will get plugged into the function and that data will appear in the email. If the user on Form_SendRequest
and clicks the button "Send email"
, "RequestEmail"
will get plugged in instead.
My last resort would be to make a new function and use the Conditions field in the Macro interface to choose between them.
I have a vague notion of setting the query names as variables and using an If statement.
Why not save the macro as code, then you can edit away to achieve say:
Function CustomEmail(NameOfQuery As String)
CurrentDB.Openrecordset(NameOfQuery)
End Function
Then, on each form in the desired event:
CustomEmail "DecisionEmail"
精彩评论