Focus on the userform

Status
Not open for further replies.
Outlook version
Email Account
Exchange Server 2007
I have created a VBA Macro which uses the ItemSend Even to modify the Subject of an email. Form within ItemSend I call a userform (ExampleForm.Show vbModal)with 3 buttons. The userform works perfectly well and when the user clicks a button the Subject is replaced and the mail is fired. However when the user clicks on the Send button and the userform comes up, the user is able to click outside the form on the mail and make changes. How can I focus only on the userform without allowing the user to click elsewhere?
 
I did it and it does not work.
I call the ExampleForm.Show vbModal from the ItemSend, when I click on the email's send button the form appears but while the form is opened I can click (outside the form) on the email and make changes.
This is what I try to avoid. I do not want the user to be able to click outside the form.
 
The code is as follows:

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
Dim strSubject As String
strSubject = Item.Subject
If Len(Trim(strSubject)) = 0 Then
prompt$ = "Subject is Empty. Are you sure you want to send the Mail?"
If MsgBox(prompt$, vbYesNo + vbQuestion + vbMsgBoxSetForeground, "Check for Subject") = vbNo Then
Cancel = True
End If
End If
If (Left(strSubject, 3) <> "P1-" And Left(strSubject, 3) <> "P2-" And Left(strSubject, 2) <> "P3-") Then
EmailPrioForm.Show vbModal
End If
End Sub
 
As mentioned, vbModal does not work. You need to replace that word by the figure 1.
 
A I mentioned, I replaced EmailPrioForm.Show vbModal

with EmailPrioForm.Show 1

and it does not work. They have exactly the same behavior.
 
How should we know if you show a different code?
Anyway, figured it, instead of calling the form directly by its name, use a variable:
dim fm as new EmailPrioForm
fm.show 1
 
Is the code running in Outlook, or in another host like Excel? If Outlook, show the code you're really using.
 
Excuse me, but what makes you believe that I'm not showing the code I'm really using...?

Outlook 2007:

ThisOutlookSession:
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
Dim strSubject As String
Dim myForm As New EmailPrioForm
strSubject = Item.Subject
If Len(Trim(strSubject)) = 0 Then
prompt$ = "Subject is Empty. Are you sure you want to send the Mail?"
If MsgBox(prompt$, vbYesNo + vbQuestion + vbMsgBoxSetForeground, "Check for Subject") = vbNo Then
Cancel = True
End If
End If
If (Left(strSubject, 3) <> "P1-" And Left(strSubject, 3) <> "P2-" And Left(strSubject, 2) <> "P3-" And Cancel <> True) Then
myForm.Show 1
End If
End Sub


EmailPrioForm:
Private Sub CommandButton1_Click()
Dim Item As MailItem
Set Item = Outlook.Application.ActiveInspector.CurrentItem
Item.Subject = "P1-" + Item.Subject
Unload Me
End Sub

' Subject Identifier: Action
Private Sub CommandButton2_Click()
Dim Item As MailItem
Set Item = Outlook.Application.ActiveInspector.CurrentItem
Item.Subject = "P2-" + Item.Subject
Unload Me
End Sub

' Subject Identifier: Decision
Private Sub CommandButton3_Click()
Dim Item As MailItem
Set Item = Outlook.Application.ActiveInspector.CurrentItem
Item.Subject = "P3-" + Item.Subject
Unload Me
End Sub
 
Because that's often the case, and here the code worked. Now I've copied all your code into my IDE, and sometimes the window is modal, sometimes it is not. I'm sorry, I don't have more ideas.
 
Hi,
I actually found the trick to work and it looks preety simple. Just had to initialise the form with a focus to one of its buttons and did the trick:

Private Sub UserForm_Initialize()
Me.CommandButton1.SetFocus
End Sub
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
Witzker Outlook 2019 Macro to check Cursor & Focus position Outlook VBA and Custom Forms 8
Witzker Set Cursor & Focus from any field to the body of a user Contact form in OL 2019 Outlook VBA and Custom Forms 1
A Outlook 2007 message search results loses focus Using Outlook 7
S Outlook: Window loses focus when typing a new message Using Outlook 3
R Focus Change from Mailheader to body Outlook VBA and Custom Forms 1
R Adding Userform Dropdown List items from names of subfolders on network drive Outlook VBA and Custom Forms 10
A Outlook Userform Size Outlook VBA and Custom Forms 2
N Activity Tracking with Userform Outlook VBA and Custom Forms 4
D Next Available Meeting with Userform Variables Outlook VBA and Custom Forms 1
A Populate Excel from Outlook Userform Outlook VBA and Custom Forms 3
B Insert Hyperlinks for attachments in Userform Outlook VBA and Custom Forms 5
D Change sender name outlook vba 2010 Custom Userform Outlook VBA and Custom Forms 1
A Open CHM file from VBA Userform Outlook VBA and Custom Forms 4
L Outlook 2007 - Userform Using Outlook 2
F Outlook 2010 - outlook userform and combo boxes Using Outlook 9
L Userform Field Month and Date. Using Outlook 19
Witzker insert Date & Time (HH:mm) no (ss) in userform Using Outlook 6
A insert Date & Time in userform Using Outlook 3
X VBA: Confused with variables between ThisOutlookSession and UserForm Using Outlook 1
L UserForm Code For Contact Links Using Outlook 76
M Progrescreas Bar in Outlook UserForm Using Outlook 1
C UserForm and ordering variables Outlook VBA and Custom Forms 3
J userform combobox Outlook VBA and Custom Forms 1
R combobox list in userform Outlook VBA and Custom Forms 1
B Userform Outlook VBA and Custom Forms 5
W Using Excel UserForm from Open Workbook in Outlook VBA Outlook VBA and Custom Forms 5
P userform in VBAProject.otm not working Outlook VBA and Custom Forms 1

Similar threads

Back
Top