PDA

View Full Version : Solved: Use of Userform rather than MSGBOX in Outlook VBA



bhoulaha
04-21-2007, 05:35 PM
I have seen many examples of the Application_ItemSend where data is entered by the user through the standard MSGBOX. I want to use a userform to gather data and pass it back to the VBA module but the variables I am assigning data to go out of context when the userform is closed.

Can anyone suggest a solution whereby I can call a userform, initilize it, have the user enter the data, then pass that data using public variables back to the ItemSend module.

Thanks in advance

Brian H.

Jacob Hilderbrand
04-21-2007, 09:09 PM
You can use a Global variable, declared at the top of a Module. Or when the data is entered in the userform instead of Unloading it, just hide it first, get the data from it, then Unload it from the Module.

bhoulaha
04-21-2007, 09:39 PM
Thanks jake,

I actually tried that, defining the global variable as intResponse in the ThisOutlookSession object like this

Public intResponse.

This was where I got to when I posted the msg.

If I try

Global intResponse, I get

"Constants, fixed-length strings, arrays, user-defined types, and Declare statements not allowed as Public members of an object module"

I also tried to define the global variable in the userform code but I get the same issue.

Perhaps this is one of those quirks to do with how Outlook handles VBA modules.

What I am trying to achieve is.

Before an email is sent I want outlook to check for a string in the subject line. If the string is not found, I want to pop up a dialog that provides two options (strings) to insert in the subject line. I can achieve this using MsgBox (Yes = String1, No=String2) but it looks tacky.

Brian H.

Jacob Hilderbrand
04-22-2007, 10:22 AM
You have to put it in a Module.


Option Explicit

Global x As String

Sub Macro1()

x = "Hi"
UserForm1.Show

End Sub



The add a UserForm called UserForm1 and put in this code:


Option Explicit

Private Sub UserForm_Click()

MsgBox x

End Sub

bhoulaha
04-23-2007, 05:06 AM
Thanks Jake,

That did the trick. I did not think of creating a separate module. Now I have a module that does all the work. I simply call the procedure from the This OutlookSession object and it works fine.

Brian H.