Access 2007 selecting record

  • Thread starter Thread starter TornadoGR4
  • Start date Start date
T

TornadoGR4

I am trying to select a record using a numerical value (General date format)
using DoCmd.FindRecord G_Date, , , acDown, , acCurrent, True . G_Date is a
variable containing the search value. The code runs with no error but does
not change the current record.
Can any one help :-)
 
Several things that could go wrong here.

Perhaps the current record is incomplete (required field not yet entered),
so it can't be saved, so the attempt to FindRecord cannot proceed.

Perhaps the date value does not match exactly - a common problem with
floating point values:
http://en.wikipedia.org/wiki/Floating_point#Accuracy_problems

Perhaps the Find is not occuring on the intended form, or the form is
filtered (or in data entry mode) so the value is not present, or ...

One of the weaknesses of FindRecord is that you don't get any feedback on
whether it succeeded. Here's an example of how you can know whether there
was a match or not:

Dim rs As DAO.Recordset
Dim strWhere As String
Const strcJetDateTime = "\#mm\/dd\/yyyy hh\:nn\:ss\#"

If Me.Dirty Then Me.Dirty = False 'Save any edits
strWhere = "[SomeField] = " & Format(G_Date, strcJetDateTime)
Set rs = Me.RecordsetClone
rs.FindFirst strWhere
If rs.NoMatch Then
MsgBox "Not found"
Else
Me.Bookmark = rs.Bookmark
End If
Set rs = Nothing

If it ends up being a floating point issue, you might try:
strWhere = "([SomeField] > " & _
Format(DateAdd("s", -1, G_Date), strcJetDateTime) & _
") AND ([SomeField] < " & _
Format(DateAdd("s", 1, G_Date), strcJetDateTime) & ")"
 
Many thanks Allen that solved my problem.

Allen Browne said:
Several things that could go wrong here.

Perhaps the current record is incomplete (required field not yet entered),
so it can't be saved, so the attempt to FindRecord cannot proceed.

Perhaps the date value does not match exactly - a common problem with
floating point values:
http://en.wikipedia.org/wiki/Floating_point#Accuracy_problems

Perhaps the Find is not occuring on the intended form, or the form is
filtered (or in data entry mode) so the value is not present, or ...

One of the weaknesses of FindRecord is that you don't get any feedback on
whether it succeeded. Here's an example of how you can know whether there
was a match or not:

Dim rs As DAO.Recordset
Dim strWhere As String
Const strcJetDateTime = "\#mm\/dd\/yyyy hh\:nn\:ss\#"

If Me.Dirty Then Me.Dirty = False 'Save any edits
strWhere = "[SomeField] = " & Format(G_Date, strcJetDateTime)
Set rs = Me.RecordsetClone
rs.FindFirst strWhere
If rs.NoMatch Then
MsgBox "Not found"
Else
Me.Bookmark = rs.Bookmark
End If
Set rs = Nothing

If it ends up being a floating point issue, you might try:
strWhere = "([SomeField] > " & _
Format(DateAdd("s", -1, G_Date), strcJetDateTime) & _
") AND ([SomeField] < " & _
Format(DateAdd("s", 1, G_Date), strcJetDateTime) & ")"

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

TornadoGR4 said:
I am trying to select a record using a numerical value (General date
format)
using DoCmd.FindRecord G_Date, , , acDown, , acCurrent, True . G_Date
is a variable containing the search value. The code runs with no error but
does not change the current record.
 
Back
Top