Re: Open User Form from Template and populate message
- From: "Michael Bauer" <mib00@xxxxxxxxxxx>
- Date: Sun, 1 May 2005 08:24:32 +0200
Hi Jason,
> If Inspector.CurrentItem.Subject = TEMPLATE_SUBJECT Then
please set a breakpoint (F9) in that line. Does the execution stops
there if you´re opening a new Inspector? If so then obviously the item´s
subject isn´t equal to the one defined in the constant.
--
Viele Grüße / Best regards
Michael Bauer - MVP Outlook
"Tahlmorrah" <Tahlmorrah@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:4D22D03C-00A5-4769-A919-26E4D729D057@xxxxxxxxxxxxxxxx
> Unfortunatly the user form is still not autoloading on open of the
template.
> What am I doing wrong?
>
> <ThisOutlookSession>
> Option Explicit
> Private WithEvents Inspectors As Outlook.Inspectors
>
> Private Sub Application_Startup()
> Set Inspectors = Application.Inspectors
> End Sub
>
> Private Sub Inspectors_NewInspector(ByVal Inspector As
Outlook.Inspector)
> If Inspector.CurrentItem.Subject = TEMPLATE_SUBJECT Then
> TSGRequest.Show 1
> End If
> End Sub
> </ThisOutlookSession>
>
> <TSGRequest>
> Private Sub CmdBtnSubmit_Click()
> Dim oMail As Outlook.MailItem
> Dim ReplaceHO As String
> Dim ReplaceHC As String
> Dim ReplaceTZ As String
> Dim ReplaceTech As String
> Dim ReplacePhone As String
> Dim ReplaceSev As String
> Dim ReplaceReason As String
> Dim ReplaceDate As String
> Dim ReplaceIssue As String
> Set oMail = Application.ActiveInspector.CurrentItem
>
> ReplaceHO = "<TxtBxHO>"
> ReplaceHC = "<TxtBxHC>"
> ReplaceTZ = "<TxtBxTZ>"
> ReplaceTech = "<TxtBxTech>"
> ReplacePhone = "<TxtBxPhone>"
> ReplaceSev = "<TxtBxSev>"
> ReplaceReason = "<TxtBxReason>"
> ReplaceDate = "<TxtBxDate>"
> ReplaceIssue = "<TxtBxIssue>"
>
> oMail.Subject = Replace(oMail.Subject, REPLACE_SUBJECT,
TxtBxCenter.Text)
> oMail.Body = Replace(oMail.Body, ReplaceHO, TxtBxHO.Text)
> oMail.Body = Replace(oMail.Body, ReplaceHC, TxtBxHC.Text)
> oMail.Body = Replace(oMail.Body, ReplaceTZ, TxtBxTZ.Text)
> oMail.Body = Replace(oMail.Body, ReplaceTech, TxtBxTech.Text)
> oMail.Body = Replace(oMail.Body, ReplacePhone, TxtBxPhone.Text)
> oMail.Body = Replace(oMail.Body, ReplaceSev, TxtBxSev.Text)
> oMail.Body = Replace(oMail.Body, ReplaceReason, TxtBxReason.Text)
> oMail.Body = Replace(oMail.Body, ReplaceDate, TxtBxDate.Text)
> oMail.Body = Replace(oMail.Body, ReplaceIssue, TxtBxIssue.Text)
>
> Unload TSGRequest
> End Sub
>
> Private Sub TSGRequest_Activate()
> TxtBxHO = "0800"
> TxtBxHC = "1700"
> TxtBxTZ = "EDT"
> TxtBxTech = "Tech Ops"
> TxtBxPhone = "800.546.8008"
> TxtBxSev = "5"
> TxtBxReason = "Center is having difficulty meeting volume"
> TxtBxDate = Date + 1
> TxtBxIssue = "Hard drive swap and minor configuration"
> End Sub
> Private Sub CmdBtnClear_Click()
> TxtBxHO = ""
> TxtBxHC = ""
> TxtBxTZ = ""
> TxtBxTech = ""
> TxtBxPhone = ""
> TxtBxSev = ""
> TxtBxReason = ""
> TxtBxDate = ""
> TxtBxIssue = ""
> End Sub
>
> </TSGRequest>
>
> <Module1>
> Public Const TEMPLATE_SUBJECT As String = "Dispatch center <
TxtBxCenter >"
> Public Const REPLACE_SUBJECT As String = "<TxtBxCenter>"
>
> </Module1>
>
> Jason
>
>
> "Michael Bauer" wrote:
>
> > Hi Jason,
> >
> > the reason for the global constant TEMPLATE_SUBJECT is that both
> > modules, ThisOutlookSession and your UserForm, can use the same
subject
> > without having to define it twice. For a global constant you´d need
a
> > standard module, which you can add to the project (Insert/Module)
and
> > name it like you want to.
> >
> > After making changes to the code you´d need to restart OL or set the
> > cursor into Application_Startup and run it manually (press F5).
> >
> > --
> > Viele Grüße
> > Michael Bauer - MVP Outlook
> >
> >
> > "Tahlmorrah" <Tahlmorrah@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
> > news:D9726C9C-C785-47FE-AA7A-878C8A818E31@xxxxxxxxxxxxxxxx
> > > Macros under Tools, Macros, Visual Basic is not displaying
> > GlobalData.bas so
> > > I am unsure of how to access this. Furthermore the form is still
not
> > popping
> > > up. I agree with your suggestions so now the code looks like
> > >
> > > <ThisOutlookSession>
> > > Option Explicit
> > > Private WithEvents Inspectors As Outlook.Inspectors
> > >
> > >
> > > Private Sub Application_Startup()
> > > Set Inspectors = Application.Inspectors
> > > End Sub
> > >
> > > Private Sub Inspectors_NewInspector(ByVal Inspector As
> > Outlook.Inspector)
> > > If Inspector.CurrentItem.Subject = TEMPLATE_SUBJECT Then
> > > TSGRequest.Show 1
> > > End If
> > > End Sub
> > > </ThisOutlookSession>
> > >
> > > <TSGRequest>
> > >
> > > Private Sub CmdBtnSubmit_Click()
> > > Dim oMail As Outlook.MailItem
> > > Dim ReplaceHO As String
> > > Dim ReplaceHC As String
> > > Dim ReplaceTZ As String
> > > Dim ReplaceTech As String
> > > Dim ReplacePhone As String
> > > Dim ReplaceSev As String
> > > Dim ReplaceReason As String
> > > Dim ReplaceDate As String
> > > Dim ReplaceIssue As String
> > > Set oMail = Application.ActiveInspector.CurrentItem
> > >
> > > TxtSubject = "Dispatch TSG Center " & TxtBxCenter
> > > ReplaceHO = "<TxtBxHO>"
> > > ReplaceHC = "<TxtBxHC>"
> > > ReplaceTZ = "<TxtBxTZ>"
> > > ReplaceTech = "<TxtBxTech>"
> > > ReplacePhone = "<TxtBxPhone>"
> > > ReplaceSev = "<TxtBxSev>"
> > > ReplaceReason = "<TxtBxReason>"
> > > ReplaceDate = "<TxtBxDate>"
> > > ReplaceIssue = "<TxtBxIssue>"
> > >
> > > oMail.Subject = TxtSubject.Text
> > > oMail.Body = Replace(oMail.Body, ReplaceHO, TxtBxHO.Text)
> > > oMail.Body = Replace(oMail.Body, ReplaceHC, TxtBxHC.Text)
> > > oMail.Body = Replace(oMail.Body, ReplaceTZ, TxtBxTZ.Text)
> > > oMail.Body = Replace(oMail.Body, ReplaceTech, TxtBxTech.Text)
> > > oMail.Body = Replace(oMail.Body, ReplacePhone,
TxtBxPhone.Text)
> > > oMail.Body = Replace(oMail.Body, ReplaceSev, TxtBxSev.Text)
> > > oMail.Body = Replace(oMail.Body, ReplaceReason,
TxtBxReason.Text)
> > > oMail.Body = Replace(oMail.Body, ReplaceDate, TxtBxDate.Text)
> > > oMail.Body = Replace(oMail.Body, ReplaceIssue,
TxtBxIssue.Text)
> > >
> > > Unload TSGRequest
> > > End Sub
> > >
> > > Private Sub TSGRequest_Activate()
> > > TxtBxHO = "0800"
> > > TxtBxHC = "1700"
> > > TxtBxTZ = "EDT"
> > > TxtBxTech = "Tech Ops"
> > > TxtBxPhone = "800.546.8008"
> > > TxtBxSev = "5"
> > > TxtBxReason = "Center is having difficulty meeting volume"
> > > TxtBxDate = Date + 1
> > > TxtBxIssue = "Hard drive swap and minor configuration"
> > > End Sub
> > > Private Sub CmdBtnClear_Click()
> > > TxtBxHO = ""
> > > TxtBxHC = ""
> > > TxtBxTZ = ""
> > > TxtBxTech = ""
> > > TxtBxPhone = ""
> > > TxtBxSev = ""
> > > TxtBxReason = ""
> > > TxtBxDate = ""
> > > TxtBxIssue = ""
> > > End Sub
> > > </TSGRequest>
> > >
> > > Understand where you are going with this, but can not figure out
why
> > it will
> > > not popup the form.
> > >
> > > Jason Dvorchak
> > >
> > >
> > >
> > > "Michael Bauer" wrote:
> > >
> > > > Hi Jason,
> > > >
> > > > you can use the NewInspector event and check its subject. For
that
> > you
> > > > need to know the item´s subject, of course.
> > > >
> > > > <GlobalData.bas>
> > > > Public Const TEMPLATE_SUBJECT as String ="Dispatch center
> > <TxtBxCenter>"
> > > > Public Const REPLACE_SUBJECT as String ="<TxtBxCenter>"
> > > > </GlobalData.bas>
> > > >
> > > > <ThisOutlookSession>
> > > > Option Explicit
> > > > Private WithEvents Inspectors As Outlook.Inspectors
> > > >
> > > > Private Sub Application_Startup()
> > > > Set Inspectors = Application.Inspectors
> > > > End Sub
> > > >
> > > > Private Sub Inspectors_NewInspector(ByVal Inspector As
> > > > Outlook.Inspector)
> > > > If Inspector.CurrentItem.Subject = TEMPLATE_SUBJECT Then
> > > > ' It´s your template. Open now your UserForm. Because I
think
> > the
> > > > user should be forced to fill in the data in TSGRequest I´d open
the
> > > > form modal instead of non-modal
> > > > TSGRequest.Show 1
> > > > End If
> > > > End Sub
> > > > </ThisOutlookSession>
> > > >
> > > > <TSGDispatch>
> > > > Private Sub CmdBtnSubmit_Click()
> > > > Dim oMail as Outlook.MailItem
> > > > Set oMail=Application.ActiveInspector.CurrentItem
> > > >
> > > > ' Sample for the Subject, assuming "txtBxCenter" is a
> > Textcontrol
> > > > oMail.Subject = Replace(oMail.Subject, REPLACE_SUBJECT,
> > > > txtBxCenter.Text)
> > > >
> > > > ' This you can repeat for every placeholder in the
MailItem´s
> > Body.
> > > > Unload TSGRequest
> > > > End Sub
> > > > </TSGDispatch>
> > > >
> > > >
> > > > --
> > > > Viele Grüße
> > > > Michael Bauer - MVP Outlook
> > > >
> > > >
> > > > "Tahlmorrah" <Tahlmorrah@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in
message
> > > > news:EBE70650-255F-4BB1-8575-005FD4964843@xxxxxxxxxxxxxxxx
> > > > > Scenario: Need to open a user form on open of Outlook Template
> > (.oft)
> > > > and
> > > > > have it auto open a UserForm to populate then have a subject
and
> > > > message body
> > > > > creaded from information entered in the UserForm.
> > > > >
> > > > > Problem: Have a standard template where the To: and CC: field
are
> > > > > semi-permanent (i.e will only change if someone leave the
company,
> > but
> > > > needs
> > > > > to be changed at template level rather than in VB). The data
in
> > the
> > > > message
> > > > > body is volitile but is consistantly the same type of
information
> > in
> > > > the same
> > > > > format...see below. Need to have a easy way to input this
> > information
> > > > into
> > > > > the e-mail and then allow changes before send.
> > > > >
> > > > > Main problem is I do not know and can not understand the
object
> > names
> > > > in
> > > > > Outlook
> > > > >
> > > > > Sample completed e-mail:
> > > > > Please dispatch Tech to center <TxtBxCenter> to complete
> > <TxtBxIssue>
> > > > > Technician must call <TxtBxTech> at <TxtBxPhone> after
equipment
> > is
> > > > > installed, for further instructions.
> > > > > Please dispatch at Severity <TxtBxSev>. <TxtBxReason>.
> > > > > Equipment will arrive <TxtBxDate> by 10:30 <TxtBxTZ>
> > > > > Center is open from <TxtBxHO> to <TxtBxHC> <TxtBxTZ>
> > > > >
> > > > > Sample Code so far:
> > > > > In Microsoft Outlook Object.This Outlook Session
> > > > > Private Sub ThisOutlookSession_Open()
> > > > > TSGRequest.Show 0 <-- Does not work
> > > > > End Sub
> > > > >
> > > > > In Forms.TSGRequest
> > > > > Private Sub CmdBtnSubmit_Click()
> > > > >
> > > > > End Sub
> > > > >
> > > > > Private Sub TSGRequest_Activate()
> > > > > TxtBxHO = "0800"
> > > > > TxtBxHC = "1700"
> > > > > TxtBxTZ = "EDT"
> > > > > TxtBxTech = "????"
> > > > > TxtBxPhone = "###.###.####"
> > > > > TxtBxSev = "5"
> > > > > TxtBxReason = "Center is having difficulty meeting volume"
> > > > > TxtBxDate = Date + 1
> > > > > TxtBxIssue = "Hard drive swap and minor configuration"
> > > > > End Sub
> > > > >
> > > > > Private Sub CmdBtnClear_Click()
> > > > > TxtBxHO = ""
> > > > > TxtBxHC = ""
> > > > > TxtBxTZ = ""
> > > > > TxtBxTech = ""
> > > > > TxtBxPhone = ""
> > > > > TxtBxSev = ""
> > > > > TxtBxReason = ""
> > > > > TxtBxDate = ""
> > > > > TxtBxIssue = ""
> > > > > End Sub
> > > > >
> > > > > Main Difficulty:
> > > > > UserForm does not autoopen when template is loaded
> > > > > Filename TSGDispatch.oft
> > > > >
> > > > > Private Sub CmdBtnSubmit_Click()
> > > > > Need to put something here to establish subject line such
as
> > > > "Dispatch
> > > > > center <TxtBxCenter>"
> > > > > Enter Message Boday <see sample completed e-mail above>
> > > > > Close TSGRequest.form
> > > > > End Sub
> > > > >
> > > > > Tons of thanks in advance. I know this can be done as I have
it
> > > > working in
> > > > > Excel and Word, jusr cannot figure out the commands for
Outlook.
> > > > >
> > > > > Jason
> > > >
> > > >
> >
> >
.
- Follow-Ups:
- Re: Open User Form from Template and populate message
- From: Tahlmorrah
- Re: Open User Form from Template and populate message
- Prev by Date: Re: VBA method to know Time Period selected from Calendar Day view
- Next by Date: Referring to an attached mail item as MailItem object??
- Previous by thread: Re: VBA method to know Time Period selected from Calendar Day view
- Next by thread: Re: Open User Form from Template and populate message
- Index(es):
Relevant Pages
|