Run time error trapping?

L

Linn Kubler

Hi,

I had my little application working. It simply copies records from one
custom public folder to another. I'm mapping differently named user defined
fields so I wrote all the code out explicitly. The only problem I was
having was that in 276 items I had two run-time errors and Outlook would
prompt me to debug or quit. I'd hit debug and then continue and everything
seemed fine.

I thought it would be a good idea to know which records were causing the
problem so I read about using the on error resume next statement and
trapping the error with an If Then statement. Now everything is falling
apart. I don't get it. Now it traps an error and then every record after
the first error fails. I now only get about half my items copied, this just
can't be right. Even worse, when I remove my error trapping code, putting
back the way it was, I only get 5 records and the rest refuse to save in the
new table.

How can I figure out what's wrong? Here's the error trapping code I added:

Do While Not PatientRecord Is Nothing

' Create new record in destination
Set newPatientRecord = newDeliveriesFolder.Items.Add

' Populate new record with data
newPatientRecord.Subject = PatientRecord.Subject
newPatientRecord.Location = PatientRecord.Location
newPatientRecord.Start = PatientRecord.Start

On Error Resume Next
newPatientRecord.Body = PatientRecord.Body
If Err.Number <> 0 Then
MsgBox ("Error No.: " & Err.Number & Chr(13) & "Patient Name: " &
PatientRecord.Subject)
Err.Clear
End If
newPatientRecord.UserProperties.Find("Team").Value =
PatientRecord.UserProperties.Find("Teams").Value
newPatientRecord.UserProperties.Find("Therapies").Value =
PatientRecord.UserProperties.Find("Therapies").Value
newPatientRecord.UserProperties.Find("Delivery").Value =
PatientRecord.UserProperties.Find("Delivery").Value
On Error Resume Next
newPatientRecord.Save
If Err.Number = -2147352567 Then
MsgBox ("Patient Name = " & PatientRecord.Subject)
Err.Clear
End If

' Get next patient in source list
Set PatientRecord = PatientList.GetNext
Loop

What am I missing here?

Thanks in advance,
Linn
 
G

Guest

My guess is an error with a user defined field on one of those items. I
suggest doing something like this instead of directly accessing the value of
a UDF from its parent item:

Dim objMyProp1 As UserProperty, objMyProp2 As UserProperty

Set objMyProp1 = PatientRecord.UserProperties("MyPropName")
Set objMyProp2 = newPatientRecord.UserProperties("MyPropName")

If Not objMyProp1 Is Nothing Then
If Not objMyProp2 Is Nothing Then
objMyProp2.Value = objMyProp1.Value
Else
Debug.Print Property not found in newPatientRecord!!!!
Stop
End If
Else
Debug.Print Property not found in newPatientRecord!!!!
Stop
End If

The Stop statement will bring you back into the editor if a problem arises
so you can inspect your variables for any problems. You may also want to use
Debug.Assert (Condition) instead, which does not cause a stop if the code is
compiled but does at design time.

You also only need to specify On Error Resume Next only once, unless you
switch to an On Error GoTo # directive.
 
L

Linn Kubler

Eric,

Thanks for the suggestion, I'll give it a try. However, the error isn't
happening on one of my user defined fields it's happening on the body, see
below where I trap the error. Since it worked before it feels like, once it
hits whatever is the original error that it derails the whole process since
it never recovers. Seems odd cause I would think that getting the next
record would straighten everything out again.

When I take the error trapping code out I get this error message:
-2147467259 Method of 'Body' of object 'AppointmentItem' failed.

Don't know if that's the source or the destination object it's referring
too. When I hit debug it points to the line:
newPatientRecord.Body = PatientRecord.Body

I'm going to poke around some more, if you think of anything please let me
know.

Thanks,
Linn
 

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