Outlook vba errror message says Access can't find my userform

M

MarceepooNu

I'm trying to create a userform in Outlook 2003 vba, that will facilitate a
secretary creating an email message about telephone calls.

I get the following error message: Microsoft Office Access can't find the
form 'frmTelMsgInput01' referred to in a macro expression or Visual Basic Code

Any help figuring out how to fix this would be much appreciated.

Thanks,
marceepooNu

Here's the code:


'The following code resides in a userform (named: frmTelMsgInput01) in the
same Outlook project as the vba code below, which in turn resides in
ThisOutlookSession
Private Sub btnCreateEmail4TelMsg_Click()
' macro created on .2008.10.03. by marc
Dim frmTelMsgInput01 As Form
Dim txCallersName As TextBox
Dim txCaseName As TextBox
Dim btnCreateEmail4TelMsg As CommandButton

Dim sCallersName As String
Dim sCaseName As String

Set txCallersName = Forms!frmTelMsgInput01!txCallersName
Set txCaseName = Forms!frmTelMsgInput01!txCaseName
'Forms!frmTelMsgInput01!lblCallersName.SetFocus


sCallersName = txCallersName.text
sCaseName = txCaseName.text

Call ThisOutlookSession.TelMsg01Part02(sCallersName, sCaseName)

Set frmTelMsgInput01 = Nothing
Set txCallersName = Nothing
Set txCaseName = Nothing
Set btnCreateEmail4TelMsg = Nothing

End Sub


Private Sub frmTelMsgInput01_Initialize()
Load frmTelMsgInput01
frmTelMsgInput01.Show
End Sub

'-------------------------------------------------------------
'The following macro invokes the userform shown above

Sub TelMsg01Part01()

'End Sub
Dim appOL As Outlook.Application
Dim objMail As MailItem
Dim insActive As Outlook.Inspector
Dim itmMail As Outlook.MailItem
Dim sEmail As String
Dim sFormat As String
Dim sInputBoxMsg1, sInputBoxMsg2, sInputBoxMsgRet As String




Set appOL = CreateObject("Outlook.application")
Set objMail = Outlook.CreateItem(olMailItem)
Set insActive = appOL.ActiveInspector
Set itmMail = insActive.CurrentItem


With itmMail
'Set body format to HTML
.BodyFormat = olFormatHTML
.HTMLBody = sFormat
'"<HTML><H2>The body of this message will appear in
HTML.</H2><BODY>Type the message text here. </BODY></HTML>"
.Display
End With

objMail.Display
objMail.ShowCategoriesDialog

frmTelMsgInput01.Show

End Sub

'-------------------------------------------------------------

Sub TelMsg01Part02(ByVal sCallersName As String, ByVal sCaseName As String)

'sCallersName, sCaseName
'InputBox(prompt[, title] [, default] [, xpos] [, ypos] [, helpfile,
context])
'sInputBoxMsg1 = "Full name of caller (Please ask him/her to spell it
unless you're absolutely certain of the spelling"
'sInputBoxMsgRet = InputBox(sInputBoxMsg1, "Caller's name & Date/Time of
Call")

sFormat = "<HTML>" & CStr(Now) & " " & _
" <strong>Caller's Full Name:</strong> " & sCallersName & _
" Re <strong>Case:</strong> " & sCaseName & _
"<br>" & vbCrLf & _
vbCrLf & _
"<br>If the caller is listed in ContactsForOfc, THEN: CLICK:
'Options', 'Contacts, " & _
" 'Folders', 'All Public Folders', 'Contacts4Ofc', and THEN
SELECT the contact. (Whew!!)<br>" & _
vbCrLf & _
"<br>If the caller is NOT listed in ContactsForOfc, please get
the following info:<br>" & vbCrLf & _
"<BLOCKQUOTE dir=ltr style=" & Chr(34) & "MARGIN-RIGHT: 0px>" &
Chr(34) & _
"Bus.Tel. <br>" & _
" Bus.Tel. <br>" & vbCrLf & _
" Cell.Tel. <br>" & vbCrLf & _
" Hom.Tel. <br>" & vbCrLf & _
" Fax.Tel. <br>" & vbCrLf & _
" Address: Street & Apt/Ste No. <br>" & vbCrLf & _
" City, State & Zip: <br><br></BLOCKQUOTE>" & vbCrLf &
vbCrLf & _
"<strong>[Please read this text to the caller: </strong>" & _
"<BLOCKQUOTE dir=ltr style=" & Chr(34) & "MARGIN-RIGHT: 0px>" &
Chr(34) & _
" Mr. Hankin asked me to request convenient times of day
when he may return your call.<br>" & _
" Mr. Hankin asked me to emphasize that he wants times of
day when you will be somewhere<br>" & _
" anyway, so that you won't be inconvenienced if some emergency
prevents him from<br>" & _
" returning your call at the expected
time.]<br><br></BLOCKQUOTE>" & vbCrLf & vbCrLf & _
" Message: </HTML>"

With itmMail
'Set body format to HTML
.BodyFormat = olFormatHTML
.HTMLBody = sFormat
'"<HTML><H2>The body of this message will appear in
HTML.</H2><BODY>Type the message text here. </BODY></HTML>"
.Display
End With


itmMail.Subject = "Tcf: " & sCallersName & " " & CStr(Now) & " Re
Case: " & sCaseName


itmMail.To = "(e-mail address removed)"
' 'This adds the text to the END of the existing message
'sEmail = itmMail.Body
' 'Add a vbcrlf before the boilerplate text
'sEmail = sEmail & sFormat & vbCrLf
'
'itmMail.Body = sEmail

' objEmail.Body.PrintText text:="Please find table below :-"
' objEmail.Body.PrintParagraph
'' wdRn.Paste ' to paste in the Word Range
' objEmail.Body.PrintParagraph
' objEmail.Body.PrintText text:="Regards etc."

End Sub
'
 
M

Michael Bauer [MVP - Outlook]

1. You shouldn't create a new Application object for Outlook. So, remove the
CreateObject line. For being able to still use the appOL variable, write
instead:

Set appOL=Application

2. Calling frmTelMsgInput01.Show loads the form automatically. So, in the
Form_Initialize, don't load it again, and don't call its Show method again.

3. The textboxes are known in the form, there's no need to use another
variable for that. So, this is all you should have in the Click event:

Private Sub btnCreateEmail4TelMsg_Click()
sCallersName = txCallersName.text
sCaseName = txCaseName.text
Call ThisOutlookSession.TelMsg01Part02(sCallersName, sCaseName)
End Sub

--
Best regards
Michael Bauer - MVP Outlook

: VBOffice Reporter for Data Analysis & Reporting
: Outlook Categories? Category Manager Is Your Tool
: <http://www.vboffice.net/product.html?pub=6&lang=en>

Am Mon, 6 Oct 2008 09:56:01 -0700 schrieb MarceepooNu:
I'm trying to create a userform in Outlook 2003 vba, that will facilitate a
secretary creating an email message about telephone calls.

I get the following error message: Microsoft Office Access can't find the
form 'frmTelMsgInput01' referred to in a macro expression or Visual Basic Code

Any help figuring out how to fix this would be much appreciated.

Thanks,
marceepooNu

Here's the code:


'The following code resides in a userform (named: frmTelMsgInput01) in the
same Outlook project as the vba code below, which in turn resides in
ThisOutlookSession
Private Sub btnCreateEmail4TelMsg_Click()
' macro created on .2008.10.03. by marc
Dim frmTelMsgInput01 As Form
Dim txCallersName As TextBox
Dim txCaseName As TextBox
Dim btnCreateEmail4TelMsg As CommandButton

Dim sCallersName As String
Dim sCaseName As String

Set txCallersName = Forms!frmTelMsgInput01!txCallersName
Set txCaseName = Forms!frmTelMsgInput01!txCaseName
'Forms!frmTelMsgInput01!lblCallersName.SetFocus


sCallersName = txCallersName.text
sCaseName = txCaseName.text

Call ThisOutlookSession.TelMsg01Part02(sCallersName, sCaseName)

Set frmTelMsgInput01 = Nothing
Set txCallersName = Nothing
Set txCaseName = Nothing
Set btnCreateEmail4TelMsg = Nothing

End Sub


Private Sub frmTelMsgInput01_Initialize()
Load frmTelMsgInput01
frmTelMsgInput01.Show
End Sub

'-------------------------------------------------------------
'The following macro invokes the userform shown above

Sub TelMsg01Part01()

'End Sub
Dim appOL As Outlook.Application
Dim objMail As MailItem
Dim insActive As Outlook.Inspector
Dim itmMail As Outlook.MailItem
Dim sEmail As String
Dim sFormat As String
Dim sInputBoxMsg1, sInputBoxMsg2, sInputBoxMsgRet As String




Set appOL = CreateObject("Outlook.application")
Set objMail = Outlook.CreateItem(olMailItem)
Set insActive = appOL.ActiveInspector
Set itmMail = insActive.CurrentItem


With itmMail
'Set body format to HTML
.BodyFormat = olFormatHTML
.HTMLBody = sFormat
'"<HTML><H2>The body of this message will appear in
HTML.</H2><BODY>Type the message text here. </BODY></HTML>"
.Display
End With

objMail.Display
objMail.ShowCategoriesDialog

frmTelMsgInput01.Show

End Sub

'-------------------------------------------------------------

Sub TelMsg01Part02(ByVal sCallersName As String, ByVal sCaseName As String)

'sCallersName, sCaseName
'InputBox(prompt[, title] [, default] [, xpos] [, ypos] [, helpfile,
context])
'sInputBoxMsg1 = "Full name of caller (Please ask him/her to spell it
unless you're absolutely certain of the spelling"
'sInputBoxMsgRet = InputBox(sInputBoxMsg1, "Caller's name & Date/Time of
Call")

sFormat = "<HTML>" & CStr(Now) & " " & _
" <strong>Caller's Full Name:</strong> " & sCallersName & _
" Re <strong>Case:</strong> " & sCaseName & _
"<br>" & vbCrLf & _
vbCrLf & _
"<br>If the caller is listed in ContactsForOfc, THEN: CLICK:
'Options', 'Contacts, " & _
" 'Folders', 'All Public Folders', 'Contacts4Ofc', and THEN
SELECT the contact. (Whew!!)<br>" & _
vbCrLf & _
"<br>If the caller is NOT listed in ContactsForOfc, please get
the following info:<br>" & vbCrLf & _
"<BLOCKQUOTE dir=ltr style=" & Chr(34) & "MARGIN-RIGHT: 0px>" &
Chr(34) & _
"Bus.Tel. <br>" & _
" Bus.Tel. <br>" & vbCrLf & _
" Cell.Tel. <br>" & vbCrLf & _
" Hom.Tel. <br>" & vbCrLf & _
" Fax.Tel. <br>" & vbCrLf & _
" Address: Street & Apt/Ste No. <br>" & vbCrLf & _
" City, State & Zip: <br><br></BLOCKQUOTE>" & vbCrLf &
vbCrLf & _
"<strong>[Please read this text to the caller: </strong>" & _
"<BLOCKQUOTE dir=ltr style=" & Chr(34) & "MARGIN-RIGHT: 0px>" &
Chr(34) & _
" Mr. Hankin asked me to request convenient times of day
when he may return your call.<br>" & _
" Mr. Hankin asked me to emphasize that he wants times of
day when you will be somewhere<br>" & _
" anyway, so that you won't be inconvenienced if some emergency
prevents him from<br>" & _
" returning your call at the expected
time.]<br><br></BLOCKQUOTE>" & vbCrLf & vbCrLf & _
" Message: </HTML>"

With itmMail
'Set body format to HTML
.BodyFormat = olFormatHTML
.HTMLBody = sFormat
'"<HTML><H2>The body of this message will appear in
HTML.</H2><BODY>Type the message text here. </BODY></HTML>"
.Display
End With


itmMail.Subject = "Tcf: " & sCallersName & " " & CStr(Now) & " Re
Case: " & sCaseName


itmMail.To = "(e-mail address removed)"
' 'This adds the text to the END of the existing message
'sEmail = itmMail.Body
' 'Add a vbcrlf before the boilerplate text
'sEmail = sEmail & sFormat & vbCrLf
'
'itmMail.Body = sEmail

' objEmail.Body.PrintText text:="Please find table below :-"
' objEmail.Body.PrintParagraph
'' wdRn.Paste ' to paste in the Word Range
' objEmail.Body.PrintParagraph
' objEmail.Body.PrintText text:="Regards etc."

End Sub
'
 
M

MarceepooNu

It occurred to me that I should mention that I am not using Access; so I
don't understand why I'm getting the error message refers to Access.
--
MarceepooNu


MarceepooNu said:
I'm trying to create a userform in Outlook 2003 vba, that will facilitate a
secretary creating an email message about telephone calls.

I get the following error message: Microsoft Office Access can't find the
form 'frmTelMsgInput01' referred to in a macro expression or Visual Basic Code

Any help figuring out how to fix this would be much appreciated.

Thanks,
marceepooNu

Here's the code:


'The following code resides in a userform (named: frmTelMsgInput01) in the
same Outlook project as the vba code below, which in turn resides in
ThisOutlookSession
Private Sub btnCreateEmail4TelMsg_Click()
' macro created on .2008.10.03. by marc
Dim frmTelMsgInput01 As Form
Dim txCallersName As TextBox
Dim txCaseName As TextBox
Dim btnCreateEmail4TelMsg As CommandButton

Dim sCallersName As String
Dim sCaseName As String

Set txCallersName = Forms!frmTelMsgInput01!txCallersName
Set txCaseName = Forms!frmTelMsgInput01!txCaseName
'Forms!frmTelMsgInput01!lblCallersName.SetFocus


sCallersName = txCallersName.text
sCaseName = txCaseName.text

Call ThisOutlookSession.TelMsg01Part02(sCallersName, sCaseName)

Set frmTelMsgInput01 = Nothing
Set txCallersName = Nothing
Set txCaseName = Nothing
Set btnCreateEmail4TelMsg = Nothing

End Sub


Private Sub frmTelMsgInput01_Initialize()
Load frmTelMsgInput01
frmTelMsgInput01.Show
End Sub

'-------------------------------------------------------------
'The following macro invokes the userform shown above

Sub TelMsg01Part01()

'End Sub
Dim appOL As Outlook.Application
Dim objMail As MailItem
Dim insActive As Outlook.Inspector
Dim itmMail As Outlook.MailItem
Dim sEmail As String
Dim sFormat As String
Dim sInputBoxMsg1, sInputBoxMsg2, sInputBoxMsgRet As String




Set appOL = CreateObject("Outlook.application")
Set objMail = Outlook.CreateItem(olMailItem)
Set insActive = appOL.ActiveInspector
Set itmMail = insActive.CurrentItem


With itmMail
'Set body format to HTML
.BodyFormat = olFormatHTML
.HTMLBody = sFormat
'"<HTML><H2>The body of this message will appear in
HTML.</H2><BODY>Type the message text here. </BODY></HTML>"
.Display
End With

objMail.Display
objMail.ShowCategoriesDialog

frmTelMsgInput01.Show

End Sub

'-------------------------------------------------------------

Sub TelMsg01Part02(ByVal sCallersName As String, ByVal sCaseName As String)

'sCallersName, sCaseName
'InputBox(prompt[, title] [, default] [, xpos] [, ypos] [, helpfile,
context])
'sInputBoxMsg1 = "Full name of caller (Please ask him/her to spell it
unless you're absolutely certain of the spelling"
'sInputBoxMsgRet = InputBox(sInputBoxMsg1, "Caller's name & Date/Time of
Call")

sFormat = "<HTML>" & CStr(Now) & " " & _
" <strong>Caller's Full Name:</strong> " & sCallersName & _
" Re <strong>Case:</strong> " & sCaseName & _
"<br>" & vbCrLf & _
vbCrLf & _
"<br>If the caller is listed in ContactsForOfc, THEN: CLICK:
'Options', 'Contacts, " & _
" 'Folders', 'All Public Folders', 'Contacts4Ofc', and THEN
SELECT the contact. (Whew!!)<br>" & _
vbCrLf & _
"<br>If the caller is NOT listed in ContactsForOfc, please get
the following info:<br>" & vbCrLf & _
"<BLOCKQUOTE dir=ltr style=" & Chr(34) & "MARGIN-RIGHT: 0px>" &
Chr(34) & _
"Bus.Tel. <br>" & _
" Bus.Tel. <br>" & vbCrLf & _
" Cell.Tel. <br>" & vbCrLf & _
" Hom.Tel. <br>" & vbCrLf & _
" Fax.Tel. <br>" & vbCrLf & _
" Address: Street & Apt/Ste No. <br>" & vbCrLf & _
" City, State & Zip: <br><br></BLOCKQUOTE>" & vbCrLf &
vbCrLf & _
"<strong>[Please read this text to the caller: </strong>" & _
"<BLOCKQUOTE dir=ltr style=" & Chr(34) & "MARGIN-RIGHT: 0px>" &
Chr(34) & _
" Mr. Hankin asked me to request convenient times of day
when he may return your call.<br>" & _
" Mr. Hankin asked me to emphasize that he wants times of
day when you will be somewhere<br>" & _
" anyway, so that you won't be inconvenienced if some emergency
prevents him from<br>" & _
" returning your call at the expected
time.]<br><br></BLOCKQUOTE>" & vbCrLf & vbCrLf & _
" Message: </HTML>"

With itmMail
'Set body format to HTML
.BodyFormat = olFormatHTML
.HTMLBody = sFormat
'"<HTML><H2>The body of this message will appear in
HTML.</H2><BODY>Type the message text here. </BODY></HTML>"
.Display
End With


itmMail.Subject = "Tcf: " & sCallersName & " " & CStr(Now) & " Re
Case: " & sCaseName


itmMail.To = "(e-mail address removed)"
' 'This adds the text to the END of the existing message
'sEmail = itmMail.Body
' 'Add a vbcrlf before the boilerplate text
'sEmail = sEmail & sFormat & vbCrLf
'
'itmMail.Body = sEmail

' objEmail.Body.PrintText text:="Please find table below :-"
' objEmail.Body.PrintParagraph
'' wdRn.Paste ' to paste in the Word Range
' objEmail.Body.PrintParagraph
' objEmail.Body.PrintText text:="Regards etc."

End Sub
'
 
M

MarceepooNu

Dear Michael:

1. Thank you. Very helpful. (I didn't see or get a notice yesterday about
your posting, but I got this one. Thank you.)
2. New error message:
"Run-time error '91':"
"Object variable or With block variable not set"
When i click on debug, this line is highlighted:
Call ThisOutlookSession.TelMsg01Part02(sCallersName, sCaseName)

I bet you'll gimme a fix; could I impose on you (if it's easy and doesn't
take much of your time) to also tell me where I could learn about the errors
I've made, so that I'd know more and do better in the future?

Thank you again for your help. It is very much appreciated.

Marc
 
M

Michael Bauer [MVP - Outlook]

Have you declared anywhere a variable called "ThisOutlookSession"?

You may learn by reading books, and a lot of excersises. For example, look
for these books:

- Absolute Beginner´s Guide to Microsoft Office Outlook 2003, by Ken Slovak
- Microsoft Outlook Programming, by Sue Mosher


--
Best regards
Michael Bauer - MVP Outlook

: VBOffice Reporter for Data Analysis & Reporting
: Outlook Categories? Category Manager Is Your Tool
: <http://www.vboffice.net/product.html?pub=6&lang=en>


Am Tue, 7 Oct 2008 11:33:01 -0700 schrieb MarceepooNu:
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top