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...
Andrew said:
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 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
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
'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
'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
'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
Set myItems = Nothing
Set MyItem = Nothing
If intFailedExports > 0 Then
'we had problems.
'TODO: Report to screen
End If
End Sub