Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Outlook / Programming VBA / October 2005

Tip: Looking for answers? Try searching our database.

getNext method?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Linn Kubler - 28 Oct 2005 17:05 GMT
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
Sue Mosher [MVP-Outlook] - 28 Oct 2005 17:16 GMT
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
Signature

Sue Mosher, Outlook MVP
  Author of Configuring Microsoft Outlook 2003
    http://www.turtleflock.com/olconfig/index.htm
  and Microsoft Outlook Programming - Jumpstart for
    Administrators, Power Users, and Developers
    http://www.outlookcode.com/jumpstart.aspx

> Hi,
>
[quoted text clipped - 31 lines]
> Thanks in advance,
> Linn
Dan Mitchell - 28 Oct 2005 17:23 GMT
> 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
[quoted text clipped - 5 lines]
> [...]
>    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
Linn Kubler - 28 Oct 2005 18:02 GMT
>> 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
[quoted text clipped - 15 lines]
>
> -- dan

Yes, thanks that was the trick.  Looks like it's working now.
Thanks much!
Linn
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.