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