Access Outlook Integration using LastModificationTime (1 Viewer)

michee

Registered User.
Local time
Today, 07:58
Joined
Sep 11, 2014
Messages
16
I am programmatically importing Outlook into Access and I want to restrict it to only those contacts that have been updated since the last import. My program has some date conversion or syntax flaw that I can't figure out. The important parts below...

DateStart = #1/1/1900#
DateStart = Nz(DMax("CMDBCreatedDateTime", "Outlook_Control"), #1/1/1900#)
MsgBox Format$(DateStart, "General Date")
' this shows I got the right date back
DateToCheck = "[LastModificationTime] > '" & Format$(DateStart, "General Date") & "'"
MsgBox DateToCheck
' this shows that the restriction looks right

Set ola = New Outlook.Application
Set olns = ola.GetNamespace("MAPI")
Set cf = olns.GetDefaultFolder(olFolderContacts)
Set objItems = cf.Items.Restrict(DateToCheck)
' initialize access import table variables

Set dbCurrent = CurrentDb
Set rstImport = dbCurrent.OpenRecordset("IMPORT_Contacts")

intItems = objItems.Count
'Let the user know what will be imported
If MsgBox(intItems & " will be imported for all changes since " & DateToCheck, 1) <> 1 Then
Exit Sub
End If
' at this point it tells me zero records. however if I change the restriction to the specific record I updated, and display the dates they show me that the dates are comparing correctly
If .LastModificationTime > DateStart Then
MsgBox ".LastModificationTime > DateStart "
End If

Any ideas?
 

vbaInet

AWF VIP
Local time
Today, 14:58
Joined
Jan 22, 2010
Messages
26,374
You would have received more responses if you had posted this question in an appropriate VBA Outlook forum.

How about this format:
Code:
DateToCheck = "[LastModificationTime] > '" & Format$(DateStart, ""ddddd h:nn AMPM") & "'"
 

michee

Registered User.
Local time
Today, 07:58
Joined
Sep 11, 2014
Messages
16
Thanks for the help! I figured access VBA forum was appropriate but probably just because I'm writing in access. I'll try that one next time. Worked like a charm! Do you know why? I'm curious to understand why the general date format wouldn't have done the trick?
 

vbaInet

AWF VIP
Local time
Today, 14:58
Joined
Jan 22, 2010
Messages
26,374
That just seems to be the acceptable format for that field and ddddd is a date formatted based on the regional settings.
 

Users who are viewing this thread

Top Bottom