Seeking critique / optimization

  • Thread starter Thread starter Scott Smith
  • Start date Start date
S

Scott Smith

Here is the current state of my first successful VBScript for my
custom contact form. Thought I'd post it for comments, and maybe some
tips for handling this more efficiently. :o)

(Stripped declarations, etc.)

BTW, this is "Function Item_Open()"



Set NS = Application.GetNamespace("MAPI")
Set itmsJournal = NS.GetDefaultFolder(11).Items

Set objContact = Item
Set oPage = Item.GetInspector.ModifiedFormPages("Marketing")
Set oMailList = oPage.controls("lstSentMailings")
Set oPhoneList = oPage.controls("lstPastCalls")

' Set 'Marketing' tab current
Item.GetInspector.SetCurrentFormPage "Marketing"


' Step through journal folder items
For lItems = 1 To itmsJournal.Count Step 1
Set olTempItem = itmsJournal(lItems)
' Check to see if a match to contact is found
If olTempItem.Links.Count > 0 Then
Set objLink = olTempItem.Links.Item(1)
If objLink = objContact Then
' Add a found mailing
If InStr(1, olTempItem.Type, "Mailed", 0) > 0 Then
oMailList.addItem olTempItem.Type & " - " & _
FormatDateTime(olTempItem.Start, vbShortDate)
Else
' Add a found phone call
If InStr(1, olTempItem.Type, "Phone", 0) > 0 Then
oPhoneList.addItem olTempItem.Type & " - " & _
FormatDateTime(olTempItem.Start, vbShortDate)

' NOTE: VBA will keep overwriting this value
' (objLastCall), therefore whatever value
' is here last will be the most recent call
Set objLastCall = olTempItem
End If
End If
End If
End If
Next


' Get notes from last call
If Not IsEmpty(objLastCall) Then
oPage.controls("txtLastCallNotes").Value = objLastCall.Body
End If





There is a brief, but tolerable delay when opening a contact as
Outlook iterates thru journal entries. It's faster than the
Activities tab, but I wouldn't mind speeding it up more if possible.
:o)

Thanks

Scott
 
You might get a marginal speed improvement by using a For Each ... Next loop
instead of For lItems = 1, but that's the only change I'd make. Nice job.
--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers



Here is the current state of my first successful VBScript for my
custom contact form. Thought I'd post it for comments, and maybe some
tips for handling this more efficiently. :o)

(Stripped declarations, etc.)

BTW, this is "Function Item_Open()"



Set NS = Application.GetNamespace("MAPI")
Set itmsJournal = NS.GetDefaultFolder(11).Items

Set objContact = Item
Set oPage = Item.GetInspector.ModifiedFormPages("Marketing")
Set oMailList = oPage.controls("lstSentMailings")
Set oPhoneList = oPage.controls("lstPastCalls")

' Set 'Marketing' tab current
Item.GetInspector.SetCurrentFormPage "Marketing"


' Step through journal folder items
For lItems = 1 To itmsJournal.Count Step 1
Set olTempItem = itmsJournal(lItems)
' Check to see if a match to contact is found
If olTempItem.Links.Count > 0 Then
Set objLink = olTempItem.Links.Item(1)
If objLink = objContact Then
' Add a found mailing
If InStr(1, olTempItem.Type, "Mailed", 0) > 0 Then
oMailList.addItem olTempItem.Type & " - " & _
FormatDateTime(olTempItem.Start, vbShortDate)
Else
' Add a found phone call
If InStr(1, olTempItem.Type, "Phone", 0) > 0 Then
oPhoneList.addItem olTempItem.Type & " - " & _
FormatDateTime(olTempItem.Start, vbShortDate)

' NOTE: VBA will keep overwriting this value
' (objLastCall), therefore whatever value
' is here last will be the most recent call
Set objLastCall = olTempItem
End If
End If
End If
End If
Next


' Get notes from last call
If Not IsEmpty(objLastCall) Then
oPage.controls("txtLastCallNotes").Value = objLastCall.Body
End If





There is a brief, but tolerable delay when opening a contact as
Outlook iterates thru journal entries. It's faster than the
Activities tab, but I wouldn't mind speeding it up more if possible.
:o)

Thanks

Scott
 
Back
Top