Moving records accurately?

L

Linn Kubler

Hi,

I'm writing a little script to move records from one public calendar to
another. I'm having a problem with accuracy though. When it is finished
runnig the two folders have the same number of records but the destination
folder is obviously wrong. It has blank subjects and some subjects are
duplicated when there's no duplicates in the source.

I can't simply drag and drop them over cause the two folders have different
custom views with different user defined fields that need to be mapped.
What kinds of tips can anyone suggest that will ensure data is mapped
accurately?

Here's the basic code I'm using:
Set orgDeliveriesFolder =
myNamespace.GetDefaultFolder(olPublicFoldersAllPublicFolders).Folders("Deliveries")

' Set the destination folder
Set newDeliveriesFolder =
myNamespace.GetDefaultFolder(olPublicFoldersAllPublicFolders).Folders("Deliveries
- Test Do Not Use")

' Read first patient record
Set PatientList = orgDeliveriesFolder.Items()
Set PatientRecord = PatientList.GetFirst

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
' newPatientRecord.Body = PatientRecord.Body
' 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
newPatientRecord.Save

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

Note that the subject field is the patient's name in the form of 'lastname,
firstname'. I commented out the other fields for debugging purposes.

This seems pretty straight forward so I don't get why the extra blank
records and records with numbers instead of names would end up in the
destination. I was wondering if there was some function that would return
the whole text of the subject field from the source folder but I can't think
of one.

Thanks in advance,
Linn
 
M

Michael Bauer

Am Mon, 31 Oct 2005 15:13:07 -0600 schrieb Linn Kubler:

Linn, do you really want to move or just to copy the items?

For copying you could shorten the code like this:

For Each PatientRecord In PatientList
Set PatientCopy = PatientRecord.Copy
PatientCopy.Move newDeliveriesFolder
Next
 
L

Linn Kubler

Michael,

Thanks for the suggestion that is much simpler. I gave it a try but
unfortunately it didn't work for me. I get a run-time error, "You cannot
post this from to this public folder. See the public folder contact." I'm
guessing this is because the two folders have different user defined fields.
Debug references the PatientCopy.Move command.

Thanks,
Linn
 
M

Michael Bauer

Am Tue, 1 Nov 2005 07:35:10 -0600 schrieb Linn Kubler:

Linn, I had to ask someone else because the Exchange isn´t my area. For the
error you´re getting, is there any form displaying modal?

Anyway, I didn´t read your first message with enough attention. Because you
want to map UserProperties with different names my sample with the Copy
function is non-sense, of course.

One point is still unclear: You wrote about "moving" records but in your
sample you´re just copying. For copying a ForEach loop can be used. For
moving records instead you need to loop backwards. So this point is
important.

Ok, here comes my new approach for *copying* the items:

For Each PatientRecord in PatientList
Set newPatientRecord = newDeliveriesFolder.Items.Add
' (copy some properties)
newPatientRecord.Subject = PatientRecord.Subject
' (Copy UserProperties)
MapUserProperty PatientRecord.UserProperties, _
"Teams", _
newPatientRecord.UserProperties, _
"Team"
newPatientRecord.Save
Next

Private Sub MapUserProperty(colOldFields as Outlook.UserProperties, _
sOldName as string, _
colNewFields as Outlook.UserProperties, _
sNewName as string _
)
Dim oOldField as Outlook.UserProperty
Dim oNewField as Outlook.UserProperty
Set oOldField=colOldFields(sOldName)
If Not oOldfield is Nothing Then
Set oNewField=colNewFields(sNewName)
If oNewField is Nothing Then
Set oNewField=colNewFields(sNewName, olText, True)
Endif
oNewField.value = oOldField.Value
Endif
End Sub
 
L

Linn Kubler

Michael,

Thanks for the help. You are right my choice of words for the subject was
inaccurate. I am trying to "copy" the records, I never like to modify the
source unless there is no other way. It turns out that my original code
works fine. I didn't realize that someone had applied a filter to the
source data view so I was only seeing part of the record set. The garbage
records I saw in the destination folder were actually accurate and they
existed in the source data.

I apologize for taking your time on what turned out to be a non-issue. I'll
keep your example code below for my records in case I need to perform a
similar task in the future.

Thanks again,
Linn
 
M

Michael Bauer

Am Fri, 4 Nov 2005 07:47:56 -0600 schrieb Linn Kubler:

Thanks for your feedback, 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