Restrict with equal on German computers

P

Peter Marchert

Hello,

I have a restrict problem on german computers only.

The following code works fine on an english system:

Sub Test1()

Dim objCalendar As Outlook.MAPIFolder
Dim objAppis As Outlook.Items
Dim strFilter As String

Set objCalendar =
Outlook.Session.GetDefaultFolder(olFolderCalendar)

strFilter = "[Start] = '" & Format("8/25/07", "ddddd h:nn AMPM") &
"'"

Set objAppis = objCalendar.Items.Restrict(strFilter)

Debug.Print objAppis.Count

End Sub

All items with the specified start date are returned. The same code on
a german system returns no items ("objAppis.Count" is always zero).

This code:

Sub Test2()

Dim objCalendar As Outlook.MAPIFolder
Dim objAppis As Outlook.Items
Dim strFilter As String

Set objCalendar =
Outlook.Session.GetDefaultFolder(olFolderCalendar)

strFilter = "[Start] > '" & Format("8/24/07", "ddddd h:nn AMPM") &
"'" & _
"AND [Start] < '" & Format("8/26/07", "ddddd h:nn AMPM") & "'"

Set objAppis = objCalendar.Items.Restrict(strFilter)

Debug.Print objAppis.Count

End Sub

returns all items between 8/25/07 and 8/26/07. So I`m afraid this is a
bug in Outlook or only a date formatting problem.

Thanks in advanced for any help!

Peter
 
K

Ken Slovak - [MVP - Outlook]

I'd guess it's the date format, but I don't have a German system here to
test on. I'd try using the format string for long date using your system
settings or maybe General Date format. Empirically I'd just use the VBA
project to set up a filter string that works (hard-coded) and then replicate
that date format with the Format function.




Hello,

I have a restrict problem on german computers only.

The following code works fine on an english system:

Sub Test1()

Dim objCalendar As Outlook.MAPIFolder
Dim objAppis As Outlook.Items
Dim strFilter As String

Set objCalendar =
Outlook.Session.GetDefaultFolder(olFolderCalendar)

strFilter = "[Start] = '" & Format("8/25/07", "ddddd h:nn AMPM") &
"'"

Set objAppis = objCalendar.Items.Restrict(strFilter)

Debug.Print objAppis.Count

End Sub

All items with the specified start date are returned. The same code on
a german system returns no items ("objAppis.Count" is always zero).

This code:

Sub Test2()

Dim objCalendar As Outlook.MAPIFolder
Dim objAppis As Outlook.Items
Dim strFilter As String

Set objCalendar =
Outlook.Session.GetDefaultFolder(olFolderCalendar)

strFilter = "[Start] > '" & Format("8/24/07", "ddddd h:nn AMPM") &
"'" & _
"AND [Start] < '" & Format("8/26/07", "ddddd h:nn AMPM") & "'"

Set objAppis = objCalendar.Items.Restrict(strFilter)

Debug.Print objAppis.Count

End Sub

returns all items between 8/25/07 and 8/26/07. So I`m afraid this is a
bug in Outlook or only a date formatting problem.

Thanks in advanced for any help!

Peter
 
S

Sue Mosher [MVP-Outlook]

Another idea: The problem may be that Find and Restrict use localized names for the fields, but there is no source of documentation for those names. I would replace Start with whatever Outlook shows as the column heading in the table view that includes the start field.
--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54


Hello,

I have a restrict problem on german computers only.

The following code works fine on an english system:

Sub Test1()

Dim objCalendar As Outlook.MAPIFolder
Dim objAppis As Outlook.Items
Dim strFilter As String

Set objCalendar =
Outlook.Session.GetDefaultFolder(olFolderCalendar)

strFilter = "[Start] = '" & Format("8/25/07", "ddddd h:nn AMPM") &
"'"

Set objAppis = objCalendar.Items.Restrict(strFilter)

Debug.Print objAppis.Count

End Sub

All items with the specified start date are returned. The same code on
a german system returns no items ("objAppis.Count" is always zero).

This code:

Sub Test2()

Dim objCalendar As Outlook.MAPIFolder
Dim objAppis As Outlook.Items
Dim strFilter As String

Set objCalendar =
Outlook.Session.GetDefaultFolder(olFolderCalendar)

strFilter = "[Start] > '" & Format("8/24/07", "ddddd h:nn AMPM") &
"'" & _
"AND [Start] < '" & Format("8/26/07", "ddddd h:nn AMPM") & "'"

Set objAppis = objCalendar.Items.Restrict(strFilter)

Debug.Print objAppis.Count

End Sub

returns all items between 8/25/07 and 8/26/07. So I`m afraid this is a
bug in Outlook or only a date formatting problem.

Thanks in advanced for any help!

Peter
 
P

Peter Marchert

Thanks Sue for this idea. Really the code woks with the local field
"Beginn" instead of "Start" but returns the same result.

Peter
 
P

Peter Marchert

Thanks for your answer, Ken.

I tried several formats and it works with the following:
Format("8/25/07", "ddddd h:nn")

I guess because German people does not have AM/PM :)

Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top