Results 1 to 2 of 2
  1. #1
    New Lounger
    Join Date
    Nov 2004
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    25-Nov-04 12:34 Accessing Outlooks Calendar (XP)

    Many thanks to Hans & Wendell for putting me on the right path.

    I have another issue that arises from that.

    Hans showed some code that accesses Outlook via MAPI and which searches the Outlook Calendar file for a particular subject.
    ie
    Dim OlApp As New Outlook.Application
    Dim nsp As NameSpace
    Dim fld As MAPIFolder
    Dim itm As Object

    Set nsp = OlApp.GetNamespace("MAPI")
    Set fld = nsp.GetDefaultFolder(olFolderCalendar)
    Set itm = fld.Items.Find("[Subject]="Budget Meeting""")
    If Not (itm Is Nothing) Then
    Debug.Print "Subject: " & itm.Subject
    Debug.Print "Start Time: " & itm.Start
    Debug.Print "Duration: " & itm.Duration
    Debug.Print "Body: " & itm.Body
    retOutlookData = True
    End If

    when running this the Immediate Window displays the items as:

    Subject: Budget Meeting
    Start Time: 27/11/2004 1:00:00 PM
    Duration: 120
    Body: Other notes

    What this displays to me is that the Start object is stored within Outlook as a date/time and duration should be a long to take into account total hours > than the integer limit.

    When I tried to input code to search by that date/time, I keep on getting runtime errors - 'Type mismatch or the value "1431655765" in the condition is not valid'
    A few questions.
    1. Does this mean that the date values are stored as Windows System Dates, ie as longs. (1431655765)
    2. If that is the case, then the code I use which passes a variable of date type (in the English/Australian date format of dd/mm/yyyy) would be incorrect. Am I right. If I am, then what would be the correct format? My thinking would be of the order yyyy/mm/dd hh:mm:ss AM/PM but I don't know. For all I know I will have to create a function that converts dates to the Windows System Date format - I have tried that elsewhere and found that while one can convert the Windows System Date to our date formats it can't be reverse engineered as the conversion makes use of the Mod function.

    Then again, I could be way off the mark so is there any way of using the Find method to search for a date within the Outook calendar?

    This is the code where I try to pass a date variable and get the above error.
    Dim OlApp As New Outlook.Application
    Dim nsp As NameSpace
    Dim fld As MAPIFolder
    Dim itm As Object
    Dim dteMeetingDate As Date

    dteMeetingDate = "27/11/2004 01:00:00"

    Set nsp = OlApp.GetNamespace("MAPI")
    Set fld = nsp.GetDefaultFolder(olFolderCalendar)
    Set itm = fld.Items.Find("[Start]=#" & dteMeetingDate & "#")
    If Not (itm Is Nothing) Then
    Debug.Print itm.Subject & " " & itm.Start & " " & itm.Duration & " " & itm.Body
    retOutlookData = True
    'itm.Duration = 120
    'itm.Save
    End If

    I get this same error when attempting to force the format 'yyyy/mm/dd hh:mm:ss)

    Cheers

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: 25-Nov-04 12:34 Accessing Outlooks Calendar (XP)

    Try the following (note the use of USA date format)
    <pre>dteMeetingDate = #11/27/2004 1:00:00 PM#
    Set itm = fld.Items.Find("[Start]='" & _
    Format(dteMeetingDate, "mm/dd/yyyy hh:mm AM/PM") & "'")</pre>


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •