pe******@yahoo. com wrote in
news:11******** **************@ f14g2000cwb.goo glegroups.com:
Would something like this work? If so, what is the proper syntax?
DoCmd.FindRecor d (Now() >= [Date1] And Now() < [Date2])
You need bookmark navigation, using the form's Recordsetclone.
With Me.RecordsetClo ne
.FindFirst "[Date1]<=#" & Date() & "# AND [Date2]>#" & Date() &
"#" If .NoMatch Then
MsgBox "No records matched your criteria."
Else
Me.Bookmark = .Bookmark
End If
End With
Now, I changed a number of things in your criteria. First, I used
Date() instead of Now(), since Now() returns a date/time, including
the time part, whereas Date() returns just the date part. If your
field is storing only dates, then you don't need to compare it to
the current date/time, just to the current date.
Secondly, I changed the order of criteria. You had them defined
backwards to my way of thinking, comparing the dynamic value to the
stored value. I guess there's actually nothing wrong with that, but
it looks wrong!
Of course, I'm not entirely certain that reversing the signs gets
exactly the same result.
It could be that this criterion definition for the .FindFirst:
Date() Between [Date1] And [Date2]
might actually work, as well, but it depends on how important the
boundary for Date2 is, because the Between operator is inclusive, if
I'm not mistaken.
Now, the other issue is that I wouldn't use bookmark navigation for
this at all, because you're not going to a single record. That is,
there could be many records that match your criteria, so you don't
know which one you're going to end up on.
For the criteria you gave, instead of sorting them and then
navigating to the first one, I'd just filter the form to display
only the records you seek. That can be done either by setting the
form's .Filter property (and then turning it on by setting
Me.FilterOn = True) to the criteria in the .FindFirst above, or by
changing the form's underlying recordsource.
I'm more likely to do the latter because I find filters to be too
easily changed or lost, with no method for undoing additional
filtering/sorting one step at a time. If you change the underlying
recordsource, the user can filter and sort the result to her heart's
content without mucking up the basic data set.
--
David W. Fenton
http://www.bway.net/~dfenton
dfenton at bway dot net
http://www.bway.net/~dfassoc