microsoft outlook macro- Runtime error 91 - Object variable not set

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • daruse712
    New Member
    • Aug 2007
    • 3

    microsoft outlook macro- Runtime error 91 - Object variable not set

    Hi there,
    I'm writing a function to search through a calendar to find any conflicting meeting times for the appointment recently recieved. Heres the code:

    Private Function isConflict(appt As Outlook.Appoint mentItem) As Boolean
    Dim strFind As String
    Dim foundAppt As Outlook.Appoint mentItem

    'string for a conflicting appointment
    'calItem.start <= appt.start < calItem.end - appointment starts between an existing meeting
    'calItem.start < appt.end <= calItem.end - appointment ends in an existing meeting
    'calItem.start > appt.start and 'calItem.end < appt.end - appointment overlaps existing meeting
    strFind = "([Start] <= '" & Format(appt.sta rt) & "'" & " and [End] > '" & Format(appt.sta rt) & "')" & _
    "or ([Start] < '" & Format(appt.End ) & "'" & " and [End] >= '" & Format(appt.End ) & "')" & _
    "or ([Start] >= '" & Format(appt.sta rt) & "'" & " and [End] <= '" & Format(appt.sta rt) & "')"

    Set foundAppt = calItems.Find(s trFind)

    'looks through the list of appointments for a conflict and skip the appointment to be scheduled
    Do Until foundAppt = "Nothing" Or Not (appt.Subject = foundAppt.Subje ct)
    Set foundAppt = calItems.FindNe xt()
    Loop
    End Function


    appt is the appointment to be accepted/declined
    calItem is a global variable initialized before the function call: Set calItems = ns.GetDefaultFo lder(olFolderCa lendar).Items

    The error occurs at the Do Until loop. I'm not finished with the coding for this loop since I'm just trying to get past this error.

    Any ideas?

    Thanks,
    Jason
  • JonJacobs
    New Member
    • Aug 2007
    • 22

    #2
    Do Until foundAppt = "Nothing" Or Not (appt.Subject = foundAppt.Subje ct)
    Set foundAppt = calItems.FindNe xt()
    Loop
    Perhaps you need short-circuit evaluation.
    The Or operator still evaluates both sides of the expression even if the first side is true, so the whole expression is true. With short-circuit evaluation, if the first side of the expression is enough to determine the overall value, the rest of the expression is not evaluated, thus protecting against evaluating something that may no longer be valid.

    You might try using OrElse instead of Or in the expression.

    HTH

    Comment

    • daruse712
      New Member
      • Aug 2007
      • 3

      #3
      I got through the error by using the Typedef function:

      Code:
          Do Until TypeName(foundAppt) = "Nothing" Or Not (TypeName(appt.Subject) = TypeName(foundAppt.Subject))
              Set foundAppt = calItems.FindNext()
          Loop
      Seems to work but I need to get the find() and findnext function to return the right items

      Comment

      Working...