Modifying AppointmentItem properties

A

Andrew Dugdell

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
 
D

David C. Holley

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.
 
A

Andrew Dugdell

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 ----
 
D

David C. Holley

Can you post the code?

Andrew said:
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 ----
 
A

Andrew Dugdell

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
 
D

David C. Holley

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
 
A

Andrew Dugdell

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
 
A

Andrew Dugdell

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 ----
David C. Holley said:
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
 

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