VBA: Confused with variables between ThisOutlookSession and UserForm

Status
Not open for further replies.

XLinho

Member
Outlook version
Outlook 2007
Email Account
Exchange Server
I like to move any sent e-mail according to three CommandButtons from a User Form.

I paste and copied the following code in ThisOutlookSession:

Public myCB As Byte



Public Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)

'I admit I have no idea about the next lines with Dim and Set, just copied it from other forums...)

Dim myOlApp As Outlook.Application, _

myOlNS As Outlook.NameSpace, _

myDestNamespace As Outlook.NameSpace, _

myDestFolder As Outlook.MAPIFolder

Set myOlApp = Outlook.Application

Set myOlNS = myOlApp.GetNamespace("MAPI")

Set myMail = myOlApp.ActiveInspector.CurrentItem

ShowUFS:

UserFormSent.Show




Select Case myCB

Case 1
'Flag for Deletion and move to the subfolder "2B-deleted" in SentItems

Set myDestFolder = myOlNS.GetDefaultFolder(olFolderSentMail).Folders("2B-deleted")

Case 2
'Move to Standard SentItems

Set myDestFolder = myOlNS.GetDefaultFolder(olFolderSentMail)

Case Else
'Pick any other folder

Set myDestFolder = myOlNS.PickFolder()

If myDestFolder Is Nothing Then

GoTo ShowUFS

End If

End Select




Set myMail.SaveSentMessageFolder = myDestFolder




End Sub

Obviously I have a UserFormSent with three CommandButtons and the following code in UserFormSent:

Sub CB_Delete_Click()

myCB = 1

UserFormSent.Hide

End Sub


_______________

Sub CB_Pick_Click()

myCB = 3

UserFormSent.Hide

End Sub


_______________

Sub CB_Sent_Click()

myCB = 2

UserFormSent.Hide

End Sub


I thought with declaring myCB as Public, myCB would keep value 1, 2 or 3 when UserFormSent gets hidden, but it doesn't. Any solutions how to solve this (or use an entire different setup)? MessageBox just doesn't work for me...
 
Status
Not open for further replies.
Top