PC Review


Reply
Thread Tools Rate Thread

Run time error trapping?

 
 
Linn Kubler
Guest
Posts: n/a
 
      8th Nov 2005
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


 
Reply With Quote
 
 
 
 
=?Utf-8?B?RXJpYyBMZWdhdWx0IFtNVlAgLSBPdXRsb29rXQ==
Guest
Posts: n/a
 
      8th Nov 2005
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.

--
Eric Legault (Outlook MVP, MCDBA, old school WOSA MCSD, B.A.)
Try Picture Attachments Wizard for Outlook:
http://www.collaborativeinnovations.ca
Blog: http://blogs.officezealot.com/legault/


"Linn Kubler" wrote:

> 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
>
>
>

 
Reply With Quote
 
Linn Kubler
Guest
Posts: n/a
 
      9th Nov 2005
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

"Eric Legault [MVP - Outlook]" <(E-Mail Removed)> wrote in
message newsED6F08F-52D9-416B-A7FD-(E-Mail Removed)...
> 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.
>
> --
> Eric Legault (Outlook MVP, MCDBA, old school WOSA MCSD, B.A.)
> Try Picture Attachments Wizard for Outlook:
> http://www.collaborativeinnovations.ca
> Blog: http://blogs.officezealot.com/legault/
>
>
> "Linn Kubler" wrote:
>
>> 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
>>
>>
>>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Convert values to time: Error Trapping Rick Rothstein Microsoft Excel Programming 0 16th Feb 2009 02:20 AM
RE: Convert values to time: Error Trapping JBeaucaire Microsoft Excel Programming 0 15th Feb 2009 10:24 PM
while deleting rows it finds an error - error trapping =?Utf-8?B?SmFuaXM=?= Microsoft Excel Programming 2 19th Jul 2007 01:12 AM
Re: Trapping Log Out Time Arvin Meyer [MVP] Microsoft Access Forms 0 6th Jan 2007 10:03 PM
Trapping Click/Command Event for run time image buttons Jim Mitchell Microsoft Dot NET 0 24th Aug 2003 10:02 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:52 PM.