Run code on form open based on referring form button (1 Viewer)

gschimek

Registered User.
Local time
Today, 16:53
Joined
Oct 2, 2006
Messages
102
I have a generic email form that I open via some buttons on a contact form. Button 1 populates the body of the email form with text 1, button 2 populates it with text 2, etc. I use it for standardized emails to individuals in my contact database.

I want to run some VBA code that attaches certain files based on which button was used to open the email form. (Button 1 on contact form attaches file 1 on email form, button 2 attaches file 2, etc).

I've tried setting a checkbox on the email form when it's opened, and running the code in the OnLoad, OnActivate, and OnOpen events if that flag is checked, but I can't get that to work. I assume it's because the checkbox doesn't get checked until the form is open, activated, or loaded.

So how to I put code on my email form saying "if button 1 was used to open this form, run the code to attach file 1?"

Or, how do I have button 1 call code directly on the email form when it opens?

Thanks in advance!
 

Addyman

Registered User.
Local time
Today, 14:53
Joined
Dec 29, 2011
Messages
90
I would maybe looking at using the OpenArgs propoerty:

http://msdn.microsoft.com/en-us/library/aa160845(v=office.10).aspx

You can essentially pass through a criteria to the Form and on the OnOpen event of your email form, you could then check the value of the OpenArgs and attach the necessary file.

You could pass through just a number identifying which button was pressed and then maybe do a Select Case on the value of the OpenArgs sent to the form.
 

gschimek

Registered User.
Local time
Today, 16:53
Joined
Oct 2, 2006
Messages
102
That sounds like a great solution. I'll give it a try. Thanks!
 

Users who are viewing this thread

Top Bottom