Les Isaacs
Registered User.
- Local time
- Today, 06:00
- Joined
- May 6, 2008
- Messages
- 186
Hi All
I have the function 'YearOfDate' below, which runs OK except that - judging by the output - the criteria is being ignored.
I know that the two 'nested' functions YearStart and YearEnd within 'YearOfDate' work perfectly.
I should add that the field 'year' in table 'months' is a text field in a very specific format, and so this can't be calculated by simply incrementing the DateIn parameter.
My function:
Public Function YearOfDate(DateIn As Date) As Variant
If Not IsDate(DateIn) Then
MsgBox (DateIn & " is not a valid date!!")
Else
Dim LowerLimit, UpperLimit As Date
Dim strCriteria As String
LowerLimit = YearStart(Format(DateIn, "mmmm yyyy"))
UpperLimit = YearEnd(Format(DateIn, "mmmm yyyy"))
YearOfDate = DMin("[months]![year]", "[months]", DateIn >= LowerLimit And DateIn <= UpperLimit)
End If
End Function
I suspect the problem lies with the delimeters in ...
YearOfDate = DMin("[months]![year]", "[months]", DateIn >= LowerLimit And DateIn <= UpperLimit)
... and have tried ...
YearOfDate = DMin("[months]![year]", "[months]", "DateIn >= '" & LowerLimit & "' And DateIn <= '" & UpperLimit & "'")
... and some other variations, but cannot get it right!
Hope someone can help.
Many thanks
Les
I have the function 'YearOfDate' below, which runs OK except that - judging by the output - the criteria is being ignored.
I know that the two 'nested' functions YearStart and YearEnd within 'YearOfDate' work perfectly.
I should add that the field 'year' in table 'months' is a text field in a very specific format, and so this can't be calculated by simply incrementing the DateIn parameter.
My function:
Public Function YearOfDate(DateIn As Date) As Variant
If Not IsDate(DateIn) Then
MsgBox (DateIn & " is not a valid date!!")
Else
Dim LowerLimit, UpperLimit As Date
Dim strCriteria As String
LowerLimit = YearStart(Format(DateIn, "mmmm yyyy"))
UpperLimit = YearEnd(Format(DateIn, "mmmm yyyy"))
YearOfDate = DMin("[months]![year]", "[months]", DateIn >= LowerLimit And DateIn <= UpperLimit)
End If
End Function
I suspect the problem lies with the delimeters in ...
YearOfDate = DMin("[months]![year]", "[months]", DateIn >= LowerLimit And DateIn <= UpperLimit)
... and have tried ...
YearOfDate = DMin("[months]![year]", "[months]", "DateIn >= '" & LowerLimit & "' And DateIn <= '" & UpperLimit & "'")
... and some other variations, but cannot get it right!
Hope someone can help.
Many thanks
Les