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 / September 2005

Tip: Looking for answers? Try searching our database.

Modifying AppointmentItem properties

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Andrew Dugdell - 28 Sep 2005 06:06 GMT
Dear All,

I'm trying to read all AppointmentItems in my calandar and export them to
sql.
Once I've exported it to SQL, I want to set the billable property so I don't
export it again.

Is this possible?  I can read everything,  I just cant write the property?

---- Original Script ----
   Set myNS = myApp.GetNamespace("MAPI")
   Set myFolder = myNS.GetDefaultFolder(olFolderCalendar)
   Set myItems = myFolder.Items
   myItems.Sort "start"

   For intLoopCounter = 2 To myItems.Count
       if instr(myItems(intLoopCounter).Categories), "billable" then
           if SubWriteTimesToSqlDatabase myItems(intLoopCounter) = true
then
               myItems(intLoopCounter).Billable = "Exported2SQL"
               myItems(intLoopCounter).save
           end if
       end if
   Next intLoopCounter

   Set myNS = Nothing
   Set myFolder = Nothing
   Set myItems = Nothing
   Set MyItem = Nothing
David C. Holley - 28 Sep 2005 14:41 GMT
I would go with a user-defined field to capture that the Item was
exported. Specifically, the field would capture the date/time the Item
was exported, just encase you need to export it again.

> Dear All,
>
[quoted text clipped - 25 lines]
>     Set myItems = Nothing
>     Set MyItem = Nothing
Andrew Dugdell - 28 Sep 2005 22:44 GMT
Hey Dave.  That bit is cool and sorted.  My problem is I can't write to any
properties.
I write the change, with no errors, but when I open outlook none of my
changes have been persisited?!

All thoughts are welcomed.

---- Original Clip ----
>I would go with a user-defined field to capture that the Item was exported.
>Specifically, the field would capture the date/time the Item was exported,
[quoted text clipped - 30 lines]
>>     Set myItems = Nothing
>>     Set MyItem = Nothing
David C. Holley - 28 Sep 2005 22:59 GMT
Can you post the code?

> Hey Dave.  That bit is cool and sorted.  My problem is I can't write to any
> properties.
[quoted text clipped - 39 lines]
>>>    Set myItems = Nothing
>>>    Set MyItem = Nothing
Andrew Dugdell - 29 Sep 2005 00:01 GMT
Hi Dave, here's the code:
PS: Thanks for helping out - greatly appreciated.

---- Original Clip ----
Sub DoExportLocalCal()
   'Take the currently logged on user an loop through all calandar
appointments
   'Validate enough information is available and submite to the database

   'assorted objects to enumerate the calandar
   Dim myApp As New Outlook.Application
   Dim myNS As NameSpace
   Dim myFolder As MAPIFolder 'Outlooks MAPI folders e.g. Inbox, Contacts,
Calendar
   Dim myItems As Items 'each mail item
   Dim MyItem As AppointmentItem 'for the individual appointments

   'Assorted working variables
   Dim intLoopCounter As Integer, intBusy As Integer
   Dim strWorking As String
   Dim intMarkedExports As Integer 'apointment items marked for export with
the 4Billing category
   Dim intActualExports 'appointment items validated and exported to the
database
   Dim intFailedExports As Integer
   Dim intAlreadyExported As Integer

   'Assorted LineItem variable to work with each calandar Entry
   Dim strJimJobNumber
   Dim strStartDate 'also know as Jim.LabourDate
   Dim strEndDate
   Dim strLabourInit
   Dim strLabourType
   Dim strComment
   Dim strSubject

  Set myNS = myApp.GetNamespace("MAPI") 'get a namespace for the data items
in the MAPI
   Set myFolder = myNS.GetDefaultFolder(olFolderCalendar) 'set the folder
as the calendar
   Set myItems = myFolder.Items ' set the myItems to be each of the
appointments in the calendar data space
   myItems.Sort "start"

   'Enumerate all the appointment items
   For intLoopCounter = 2 To myItems.Count

       'Does the AppointmentItem have "4Billing" in the categories
       If InStr(myItems(intLoopCounter).Categories, "4Billing") Then

           If InStr(LCase(myItems(intLoopCounter).BillingInformation),
LCase("Exported")) Then
               intAlreadyExported = intAlreadyExported + 1
               frmMain.Caption = "skipping " & intAlreadyExported & "
items."
               GoTo jumpEntryPoint  'HACK: I so have to fix this
               Beep
           End If

           'Ok we should process this and validate it for export
           intMarkedExports = intMarkedExports + 1

           strSubject = myItems(intLoopCounter).Subject
           strJimJobNumber =
GoGetJimJobNumber(myItems(intLoopCounter).Subject)
           strStartDate = GoGetStartDate(myItems(intLoopCounter).Start)
           strEndDate = GoGetEndDate(myItems(intLoopCounter).End)
           strLabourType =
GoGetLabourType(myItems(intLoopCounter).Categories)
           strComment = GoGetComment(myItems(intLoopCounter).Body)
           'TODO:  Causes outlook violation thingy, make sure you code sign
this later.

               If ExportToDatabase(strJimJobNumber, strStartDate,
strEndDate, strLabourType, strComment) = True Then
                   intActualExports = intActualExports + 1
                   myItems(intLoopCounter).BillingInformation = "Exported"
                   myItems(intLoopCounter).Save

               End If

       Else
           'Nope: no 4Billing = no bother

       End If

jumpEntryPoint:
   Next intLoopCounter ' Iterate through to the next appointment item

   Set myNS = Nothing ' always clear up after!
   Set myFolder = Nothing
   Set myItems = Nothing
   Set MyItem = Nothing

   If intFailedExports > 0 Then
       'we had problems.
       'TODO:  Report to screen
   End If

End Sub
David C. Holley - 29 Sep 2005 02:08 GMT
Try accessing the AppointmentItem via an Object variable. I'm thinking
that that may be were the problem is. See below for some additional
edits/comments...

> Hi Dave, here's the code:
> PS: Thanks for helping out - greatly appreciated.
[quoted text clipped - 41 lines]
>
>     'Enumerate all the appointment items
                           2?????
>     For intLoopCounter = 2 To myItems.Count

      'FYI i is pretty much universally assumed to be the counter for a
loop and saves a lot of typing
    Set myItem = myItems(i)

>         'Does the AppointmentItem have "4Billing" in the categories
      'May want to test the .Class property to confirm that the item
is of the type that you expect olAppointment (check out Outlook help for
the other values)
    'Unless I missed it elsewhere, but I think this is what you missed
    Set myItem = myItems(intLoopCounter)

With myItem
'makes life easier in that you can access the properties by simply using
a [.] and the property name, change the reference appropriately
.Subject
.To
.From
.BillingInformation

>         If InStr(myItems(intLoopCounter).Categories, "4Billing") Then
>
[quoted text clipped - 5 lines]
>                 GoTo jumpEntryPoint  'HACK: I so have to fix this
>                 Beep
'add ELSE here to avoid using the GoTo statement and move the
'End if down to the bottom.
IF [Statement is true] THEN
    [Execute this code]
ELSE
    [execute this code]
END IF
>             End If
>
[quoted text clipped - 24 lines]
>
>         End If

  '1 - GoTos are bad, bad, bad
  '2 - from above the End If should go hear
> jumpEntryPoint:
>     Next intLoopCounter ' Iterate through to the next appointment item
end with

>     Set myNS = Nothing ' always clear up after!
>     Set myFolder = Nothing
[quoted text clipped - 7 lines]
>
> End Sub
Andrew Dugdell - 29 Sep 2005 04:30 GMT
Chuckle - yeah ok, busted - I deserve to be flamed for using a goto.
..and I deserve another roasting for not using the with keyword as well.

Just going through your comments now.  Post back when I've been through it
all.
Thanks again
David C. Holley - 29 Sep 2005 05:18 GMT
Its not a bad thing when used with Error handling.

> Chuckle - yeah ok, busted - I deserve to be flamed for using a goto.
> ..and I deserve another roasting for not using the with keyword as well.
>
> Just going through your comments now.  Post back when I've been through it
> all.
> Thanks again
Andrew Dugdell - 29 Sep 2005 04:50 GMT
Hey David it works.  Made those changes you suggested and it works a treat.
Personally I think it was the "GOTO" statement that broke everything :)
I will clean the code up and  post it back here, for everyone else.

thanks again!

- Dugie

---- Original Clip ----
> Try accessing the AppointmentItem via an Object variable. I'm thinking
> that that may be were the problem is. See below for some additional
[quoted text clipped - 130 lines]
>>
>> End Sub
 
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.