getNext method?

L

Linn Kubler

Hi,

I seem to be having trouble with the getNext method. In my routine I'm
simply trying to read out the first 10 entries in my folder. I go to the
first record, then enter a for loop and loop 10 times using getNext.
Problem is that it shows one record, then the next and then it keeps showing
the same record for the 10 iterations. Am I doing something wrong in my
code? Here it is:

Set myolApp.ActiveExplorer.CurrentFolder = _
myNamespace.GetDefaultFolder(olPublicFoldersAllPublicFolders).Folders("Deliveries")

Set orgDeliveriesFolder =
myNamespace.GetDefaultFolder(olPublicFoldersAllPublicFolders).Folders("Deliveries")
Set PatientRecord = orgDeliveriesFolder.Items().GetFirst

MsgBox ("Deliveries Folder Name = " & orgDeliveriesFolder.Name _
& Chr(13) & "No. of Patients = " &
orgDeliveriesFolder.Items().Count)

For I = 1 To 10

MsgBox ("Patient Name = " & PatientRecord.Subject & Chr(13) & _
"Location = " & PatientRecord.Location & Chr(13) & _
"Start = " & PatientRecord.Start & Chr(13) & _
"Categories = " & PatientRecord.Categories + Chr(13) & _
"Message = " & PatientRecord.Body)
' "Assessment Due = " & PatientRecord.UserProperties.Find("Assessment
Due") & Chr(13) & _

Set PatientRecord = orgDeliveriesFolder.Items().GetNext
Next I

Thanks in advance,
Linn
 
S

Sue Mosher [MVP-Outlook]

You need an explicit Items object and should use GetFirst to get the first item:

Set delItems = orgDeliveriesFolder.Items
Set PatientRecord = delItems.GetFirst
For I = 1 To 9
' do stuff with PatientRecord
Set PatientRecord = orgDeliveriesFolder.Items().GetNext
Next I
--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
D

Dan Mitchell

Linn Kubler said:
I seem to be having trouble with the getNext method. In my routine
I'm simply trying to read out the first 10 entries in my folder. I go
to the first record, then enter a for loop and loop 10 times using
getNext. Problem is that it shows one record, then the next and then
it keeps showing the same record for the 10 iterations.
[...]
For I = 1 To 10
[...]
Set PatientRecord = orgDeliveriesFolder.Items().GetNext

That's because you're calling Items().GetNext -- each time you call Items
(), you get a fresh instance of that thing, so each GetNext() call starts
from the beginning.

You need to move Items() out of the loop and assign it to a variable
there; that way it'll be the same one that has GetNext() called on it each
time.

-- dan
 
L

Linn Kubler

Dan Mitchell said:
Linn Kubler said:
I seem to be having trouble with the getNext method. In my routine
I'm simply trying to read out the first 10 entries in my folder. I go
to the first record, then enter a for loop and loop 10 times using
getNext. Problem is that it shows one record, then the next and then
it keeps showing the same record for the 10 iterations.
[...]
For I = 1 To 10
[...]
Set PatientRecord = orgDeliveriesFolder.Items().GetNext

That's because you're calling Items().GetNext -- each time you call Items
(), you get a fresh instance of that thing, so each GetNext() call starts
from the beginning.

You need to move Items() out of the loop and assign it to a variable
there; that way it'll be the same one that has GetNext() called on it each
time.

-- dan

Yes, thanks that was the trick. Looks like it's working now.
Thanks much!
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