Focus on the userform

Status
Not open for further replies.
Outlook version
Outlook 2007
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?
 
Outlook version
Outlook 2007
Email Account
Exchange Server 2007
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.
 
Outlook version
Outlook 2007
Email Account
Exchange Server 2007
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
 

Michael Bauer

Senior Member
Outlook version
Outlook 2010 32 bit
Email Account
Exchange Server
As mentioned, vbModal does not work. You need to replace that word by the figure 1.
 
Outlook version
Outlook 2007
Email Account
Exchange Server 2007
A I mentioned, I replaced EmailPrioForm.Show vbModal

with EmailPrioForm.Show 1

and it does not work. They have exactly the same behavior.
 

Michael Bauer

Senior Member
Outlook version
Outlook 2010 32 bit
Email Account
Exchange Server
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
 

Michael Bauer

Senior Member
Outlook version
Outlook 2010 32 bit
Email Account
Exchange Server
Is the code running in Outlook, or in another host like Excel? If Outlook, show the code you're really using.
 
Outlook version
Outlook 2007
Email Account
Exchange Server 2007
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
 

Michael Bauer

Senior Member
Outlook version
Outlook 2010 32 bit
Email Account
Exchange Server
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.
 
Outlook version
Outlook 2007
Email Account
Exchange Server 2007
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.
Thread starter Similar threads Forum Replies Date
A Outlook 2007 message search results loses focus Using Outlook 7
R Way to correct the window in focus when creating a task from email? Using Outlook 1
J Outlook looses and regains focus. Using Outlook 2
S Sync my samsung focus phone with Outlook 2003. Using Outlook 3
L sync Outlook 2003 with WP7 Samsung Focus phone Using Outlook 1
D Outlook 2007: cycles in out of focus. Using Outlook 1
N I use the keyboard to delete emails and every so often the focus changes to the reminders window and I delete reminders by mistake Using Outlook 1
I Sync Home PC with new cell phone Samsung Focus to use Outlook/office. Have Mobil device on PC; it wo Using Outlook 3
J Re: Outlook loses focus whilst composing email Using Outlook 2
T Outlook loses focus whilst composing email Using Outlook 0
J Outlook 2010 Month view, today highlight/focus color Using Outlook 4
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
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


































Top