Errors in sending a post form in Outlook 2k

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a post form that was created by previous programmer and I am trying to
figure out why I am getting these errors. Below are the messages appeared in
the same form. I am learning VBA and the Outlook functinoally so bear with
me. I am still looking through the VBA script code. Can anyone point out
what the resolution and the direction I need to go in order to troubleshoot
this issue.

"The messaging interface has returned an unknown error. If the problem
persists, restart Outlook."
This happen when I click the 'submit' button in the form.

"The operation failed. An object could not be found."
This happen when I click the 'create' button in the form.

"Array index out of bounds"
This happen when I click the 'create' button in the form.

"Object required: 'ItemAttachment' "
This happen when I click the 'submit' button then the 'show' button in the
form.
 
All those errors except for the first one sound like problems with the specific code on that form. The error messages should also give you line numbers. You can use those to find the problem statements in context, which is the first step to resolving the problems.

Note that code behind an Outlook custom form is VBScript, not VBA.

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
Sue,
There was no line number given along with the error message. So, I had to
read the script code manually and figure out where it occured. As for the
for error message
"The messaging interface has returned an unknown error. If the problem
persists, restart Outlook." How would I go around this error message?
 
Sue's away.

Post the code from the form, or a part of it if it's long. Point out what
line causes the error.
 
Ok,

Here are the variable defined and code fragment.

Dim sCombination
Dim nPosition
Dim MyNameSpace
Dim MyApplication
Dim MyInspector
Dim sAttachmentDisplayName
Dim MyWord
Dim MyDoc
''Dim sDocumentLocation
Dim sTemplatePathName
Dim Hospital_Folders
Dim PageDocument
Dim CarrierToClose
Dim MyAddressList

Dim bDebug

------- Below is the code fragment (this appear after the above code)
-----------

Function Item_Read()
bDebug = DebugMode
If bDebug Then MsgBox "Item_Read"
End Function

Function Item_Open()
bDebug = DebugMode
Set MyNameSpace = Application.GetNameSpace("MAPI")
' Test AddressLists - Begin
' For Each MyAddressList In MyNameSpace.AddressLists
' MsgBox "I See AddressList :: " & MyAddressList.Name
' Next

Set MyAddressList = MyNameSpace.AddressLists("Global Address List")
' Set MyDistrList = MyAddressList.AddressEntries("Vice_Presidents")
' For Each MyVicePresident In MyDistrList.Members
' MsgBox " I see Vice President :: " & MyVicePresident.Name
' Next
' Test AddressLists - End
If bDebug Then
MsgBox "Item_Open Event"
Set PageDocument = GetInspector.ModifiedFormPages("Document")
PageDocument.Controls("Label11").Visible = True
PageDocument.Controls("TextBox11").Visible = True
PageDocument.Controls("Label12").Visible = True
PageDocument.Controls("TextBox12").Visible = True
PageDocument.Controls("Label13").Visible = True
PageDocument.Controls("TextBox4").Visible = True
PageDocument.Controls("Label14").Visible = True
PageDocument.Controls("TextBox2").Visible = True
PageDocument.Controls("CommandButtonTest").Visible = True
End If
Set CarrierToClose = Nothing
' For Each MyItem In
MyNameSpace.GetDefaultFolder(6).Items.Restrict("[Subject]='Document Handling
Notification'")
' MsgBox MyItem.Categories
' Next
sCurrentUserName = MyNameSpace.CurrentUser.Name
If bDebug Then MsgBox "Current User Name :: " & sCurrentUserName
Set MyInspector = GetInspector
sAttachmentDisplayName = "Recruitment Requisition"
sTemplatePathName = "C:\Temp\Templates\" & sAttachmentDisplayName & "T.dot"
'' sDocumentLocation = "C:\Temp\" & sAttachmentDisplayName & "D.doc"
RestrictCommandBars
SetRootFolder
' MsgBox "Unread :: " & Unread
If bDebug Then MsgBox "Sender Name :: " & SenderName
If UserProperties.Find("RequisitionFrom") = "" Then
UserProperties.Find("RequisitionFrom") = sCurrentUserName
End If

' If SenderName = "" Or UserProperties.Find("RequisitionFrom")=
sCurrentUserName Then
' If bDebug Then MsgBox "Expose to Author"
' ExposeToAuthor
' Else
' If bDebug Then MsgBox "NextToSign :: " & UserProperties.Find("NextToSign")
' If UserProperties.Find("Submitted") And UserProperties.Find("NextToSign")
= sCurrentUserName Then
' ExposeForSigning
' Else
' If bDebug Then MsgBox "Disable Everything"
' Alive( False )
' End If
' End If

If SenderName = "" Then
If bDebug Then MsgBox "Expose to Author"
ExposeToAuthor
Else
If bDebug Then MsgBox "NextToSign :: " & UserProperties.Find("NextToSign")
If UserProperties.Find("Submitted") And UserProperties.Find("NextToSign")
= sCurrentUserName Then
ExposeForSigning
Else
If UserProperties.Find("RequisitionFrom")= sCurrentUserName Then
If bDebug Then MsgBox "Expose to Author"
ExposeToAuthor
Else
If bDebug Then MsgBox "Disable Everything"
Alive( False )
End If
End If
End If

End Function
 
And what code lines produce the errors?

One thing I'd do to try to make troubleshooting the code easier is to not
use so many dot operators. It makes it very hard to know what's failing
where. Use a separate variable for each dot operator so you can always test
if that piece of the puzzle is being instantiated correctly, is nothing or
is throwing an exception.

Please leave parts of the preceding thread in your posts, it makes it very
hard to follow a thread when you don't.




Desiboy said:
Ok,

Here are the variable defined and code fragment.

Dim sCombination
Dim nPosition
Dim MyNameSpace
Dim MyApplication
Dim MyInspector
Dim sAttachmentDisplayName
Dim MyWord
Dim MyDoc
''Dim sDocumentLocation
Dim sTemplatePathName
Dim Hospital_Folders
Dim PageDocument
Dim CarrierToClose
Dim MyAddressList

Dim bDebug

------- Below is the code fragment (this appear after the above code)
-----------

Function Item_Read()
bDebug = DebugMode
If bDebug Then MsgBox "Item_Read"
End Function

Function Item_Open()
bDebug = DebugMode
Set MyNameSpace = Application.GetNameSpace("MAPI")
' Test AddressLists - Begin
' For Each MyAddressList In MyNameSpace.AddressLists
' MsgBox "I See AddressList :: " & MyAddressList.Name
' Next

Set MyAddressList = MyNameSpace.AddressLists("Global Address List")
' Set MyDistrList = MyAddressList.AddressEntries("Vice_Presidents")
' For Each MyVicePresident In MyDistrList.Members
' MsgBox " I see Vice President :: " & MyVicePresident.Name
' Next
' Test AddressLists - End
If bDebug Then
MsgBox "Item_Open Event"
Set PageDocument = GetInspector.ModifiedFormPages("Document")
PageDocument.Controls("Label11").Visible = True
PageDocument.Controls("TextBox11").Visible = True
PageDocument.Controls("Label12").Visible = True
PageDocument.Controls("TextBox12").Visible = True
PageDocument.Controls("Label13").Visible = True
PageDocument.Controls("TextBox4").Visible = True
PageDocument.Controls("Label14").Visible = True
PageDocument.Controls("TextBox2").Visible = True
PageDocument.Controls("CommandButtonTest").Visible = True
End If
Set CarrierToClose = Nothing
' For Each MyItem In
MyNameSpace.GetDefaultFolder(6).Items.Restrict("[Subject]='Document
Handling
Notification'")
' MsgBox MyItem.Categories
' Next
sCurrentUserName = MyNameSpace.CurrentUser.Name
If bDebug Then MsgBox "Current User Name :: " & sCurrentUserName
Set MyInspector = GetInspector
sAttachmentDisplayName = "Recruitment Requisition"
sTemplatePathName = "C:\Temp\Templates\" & sAttachmentDisplayName &
"T.dot"
'' sDocumentLocation = "C:\Temp\" & sAttachmentDisplayName & "D.doc"
RestrictCommandBars
SetRootFolder
' MsgBox "Unread :: " & Unread
If bDebug Then MsgBox "Sender Name :: " & SenderName
If UserProperties.Find("RequisitionFrom") = "" Then
UserProperties.Find("RequisitionFrom") = sCurrentUserName
End If

' If SenderName = "" Or UserProperties.Find("RequisitionFrom")=
sCurrentUserName Then
' If bDebug Then MsgBox "Expose to Author"
' ExposeToAuthor
' Else
' If bDebug Then MsgBox "NextToSign :: " &
UserProperties.Find("NextToSign")
' If UserProperties.Find("Submitted") And
UserProperties.Find("NextToSign")
= sCurrentUserName Then
' ExposeForSigning
' Else
' If bDebug Then MsgBox "Disable Everything"
' Alive( False )
' End If
' End If

If SenderName = "" Then
If bDebug Then MsgBox "Expose to Author"
ExposeToAuthor
Else
If bDebug Then MsgBox "NextToSign :: " & UserProperties.Find("NextToSign")
If UserProperties.Find("Submitted") And UserProperties.Find("NextToSign")
= sCurrentUserName Then
ExposeForSigning
Else
If UserProperties.Find("RequisitionFrom")= sCurrentUserName Then
If bDebug Then MsgBox "Expose to Author"
ExposeToAuthor
Else
If bDebug Then MsgBox "Disable Everything"
Alive( False )
End If
End If
End If

End Function
 
Ken,
Ok, I understand. I found the method that may link to "The operation
failed. An object cannot be found." Sorry if there are too many dot
operator. Let me know how I should troubleshoot since it didn't give me the
line number for the error message. I will continue troubleshooting this and
other error messages

Sub cmdCreate_Click
If bDebug Then MsgBox "cmdCreate_Click"
If WordOpen Then Exit Sub
Set ItemAttachment = ExistingItemAttachment( sAttachmentDisplayName )
If ItemAttachment Is Nothing Then
CreateAndAttach sAttachmentDisplayName
Save
End If
Set ItemAttachment = ExistingItemAttachment( sAttachmentDisplayName )
ItemAttachment.SaveAsFile sDocumentLocation
Set MyWord = CreateObject("Word.Application")
MyWord.Documents.Open sDocumentLocation
Set MyDoc = MyWord.ActiveDocument
'' MyDoc.Unprotect
FromOutlookToWordDoc

PageDocument.Controls("cmdDocumentShow").Enabled = True
PageDocument.Controls("cmdSubmit").Enabled = True
PageDocument.Controls("cmdCreate").Caption = "Update"

MyDoc.CustomDocumentProperties("StoreID") = Parent.StoreID
MyDoc.CustomDocumentProperties("EntryID") = Item.EntryID

MyWord.ActiveDocument.Save
MyWord.ActiveDocument.Protect 2, True
MyWord.Visible = True
End Sub
 
I still have no idea what's throwing any errors or where they might be.

For dot operators, instead of for example:
Set oItem = oNS.GetDefaultFolder(olFolderInbox).Items.Item(1)
use this:
Set oFolder = oNS.GetDefaultFolder(olFolderInbox)
Set oItems = oFolder.Items
Set oItem = oItems.Item(1)

That way you can step the code or breakpoint in the code and see if each
intermediate object is being instantiated or throws any errors.

For debugging something like this I usually put a Stop statement in my code.
I also comment out any error handler in the procedure. The Stop statement
throws an error, that opens the debugger and I can test things, check values
and objects in the Immediate window and step the code to see exactly where
any errors are occurring.
 
Back
Top