Maddiegirl
asked on
Runtime Error 91 object variable not found
Within the last 6 months we've upgraded from exchange 5.5 and access 97 to exchange 2003 and access 2003.
In our exchange environment, we have public folder that people post employee file notes to - incident reports, good job, etc - via an outlook form that we designed some time ago.
In the access database that keeps all of this information there is an import function. A employee in hr would click import and it would write all of this information to the access database, each record being a separate email in the public folder where it pulls from.
Now, since the upgrade, I keep getting the error: runtime error 91 object variable or with block variable not set.
When you click debug, it brings you to the vb code behind this database, which is posted below.
The debugger is pointing to the following line as being the problem:
If objItems(i).UserProperties ("Exported ") = 0 Then
The whole code is below.
Option Compare Database
Option Explicit
Sub ImportFileNotesFromOutlook ()
' Set up DAO objects (uses existing "FileNotes" table
Dim rst As DAO.Recordset
Set rst = CurrentDb.OpenRecordset("F ileNotes")
' Set up Outlook objects
Dim ol As New Outlook.Application
Dim olns As Outlook.NameSpace
Dim cf As Outlook.MAPIFolder
Dim c As Outlook.MailItem
Dim objItems As Outlook.Items
Dim Prop As Outlook.UserProperty
Dim iNum As Integer
Dim i As Integer
Set olns = ol.GetNamespace("MAPI")
Set cf = olns.Folders("Public Folders").Folders("All Public Folders").Folders("Employe e File Notes")
Set objItems = cf.Items
iNum = objItems.Count
If iNum > 0 Then
For i = 1 To iNum
If objItems(i).UserProperties ("Exported ") = 0 Then
Set c = objItems(i)
rst.AddNew
rst!EENumber = c.UserProperties("Employee Number")
rst!EmployeeName = c.UserProperties("Employee Name")
rst!Department = c.UserProperties("Employee Department ")
rst!WrittenBy = c.UserProperties("Written By")
rst!EmployeeNumber = c.UserProperties("Employee Number of Writer")
rst!DateAndTimeOfEvent = c.UserProperties("Event Date and Time")
rst!AreaObserved = c.UserProperties("Area Observed")
rst!Description = c.UserProperties("Descript ion of Event")
rst!CorrectiveActionTaken = c.UserProperties("Correcti ve Action Taken")
rst!FollowUpRequired = c.UserProperties("Follow up required")
rst!FollowUpTime = c.UserProperties("Follow-u p Time")
rst.Update
c.UserProperties("Exported ") = -1
c.Save
End If
Next i
rst.Close
MsgBox "Finished."
Else
MsgBox "No File Notes to export."
End If
End Sub
Private Sub cmdimport_Click()
'On Error GoTo Err_cmdImport_Click
'
ImportFileNotesFromOutlook
'
'Exit_cmdImport_Click:
' Exit Sub
'
'Err_cmdImport_Click:
' MsgBox Err.Description
' Resume Exit_cmdImport_Click
'
End Sub
Please help. This looks just fine to me.....and it worked for years before the upgrade.
Thanks!
In our exchange environment, we have public folder that people post employee file notes to - incident reports, good job, etc - via an outlook form that we designed some time ago.
In the access database that keeps all of this information there is an import function. A employee in hr would click import and it would write all of this information to the access database, each record being a separate email in the public folder where it pulls from.
Now, since the upgrade, I keep getting the error: runtime error 91 object variable or with block variable not set.
When you click debug, it brings you to the vb code behind this database, which is posted below.
The debugger is pointing to the following line as being the problem:
If objItems(i).UserProperties
The whole code is below.
Option Compare Database
Option Explicit
Sub ImportFileNotesFromOutlook
' Set up DAO objects (uses existing "FileNotes" table
Dim rst As DAO.Recordset
Set rst = CurrentDb.OpenRecordset("F
' Set up Outlook objects
Dim ol As New Outlook.Application
Dim olns As Outlook.NameSpace
Dim cf As Outlook.MAPIFolder
Dim c As Outlook.MailItem
Dim objItems As Outlook.Items
Dim Prop As Outlook.UserProperty
Dim iNum As Integer
Dim i As Integer
Set olns = ol.GetNamespace("MAPI")
Set cf = olns.Folders("Public Folders").Folders("All Public Folders").Folders("Employe
Set objItems = cf.Items
iNum = objItems.Count
If iNum > 0 Then
For i = 1 To iNum
If objItems(i).UserProperties
Set c = objItems(i)
rst.AddNew
rst!EENumber = c.UserProperties("Employee
rst!EmployeeName = c.UserProperties("Employee
rst!Department = c.UserProperties("Employee
rst!WrittenBy = c.UserProperties("Written By")
rst!EmployeeNumber = c.UserProperties("Employee
rst!DateAndTimeOfEvent = c.UserProperties("Event Date and Time")
rst!AreaObserved = c.UserProperties("Area Observed")
rst!Description = c.UserProperties("Descript
rst!CorrectiveActionTaken = c.UserProperties("Correcti
rst!FollowUpRequired = c.UserProperties("Follow up required")
rst!FollowUpTime = c.UserProperties("Follow-u
rst.Update
c.UserProperties("Exported
c.Save
End If
Next i
rst.Close
MsgBox "Finished."
Else
MsgBox "No File Notes to export."
End If
End Sub
Private Sub cmdimport_Click()
'On Error GoTo Err_cmdImport_Click
'
ImportFileNotesFromOutlook
'
'Exit_cmdImport_Click:
' Exit Sub
'
'Err_cmdImport_Click:
' MsgBox Err.Description
' Resume Exit_cmdImport_Click
'
End Sub
Please help. This looks just fine to me.....and it worked for years before the upgrade.
Thanks!
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
I found one record that was causing the 3163 error when trying to do the import. Thank you for your help there.
Sadly I am not back to the error 91 on the same line, even after changing
If objItems(i).UserProperties ("Exported ") = 0 Then
to If cf.Items(i).UserProperties ("Exported ") Then
per cool12399's suggestion. Can you explain a bit more about option b?
Some of the data did import.
Thanks.
Sadly I am not back to the error 91 on the same line, even after changing
If objItems(i).UserProperties
to If cf.Items(i).UserProperties
per cool12399's suggestion. Can you explain a bit more about option b?
Some of the data did import.
Thanks.
ASKER
Thanks for your help, guys. I was able to figure it out with your assitance.
ASKER
I now have another, same database. Care to take a look?
Run-time error 3163 The field is too small to accept the amount of data you attempted to add. Try inserting or pasting less data.
It's triggering on the line:
rst!EmployeeName = c.UserProperties("Employee
Thanks.