开发者

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").

Now I want to make a different query ("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"
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜