Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

DoCmd.Findrecord. How do you specify the field.

35 views
Skip to first unread message

FireyColin

unread,
Feb 2, 2012, 9:19:47 AM2/2/12
to
After you a command button to requery the data I want to return to the
record I have been working in but at present it just goes to the first
record in the background table. Do I use 'Findrecord', and if so how
do I specify which field contains the unique identifier?

The column containing the unique identifier is called
'unique_record_number' and the text box on the form is named
'txtURN_1'.

christi...@yahoo.com

unread,
Feb 2, 2012, 12:37:57 PM2/2/12
to

Where FieldName is the name of your ID field -

If text field:

Me.Recordset.FindFirst "FieldName='" & strInput & "'"

Else:

Me.Recordset.FindFirst "FieldName=" & strInput

Jan T

unread,
Feb 2, 2012, 1:01:58 PM2/2/12
to
Yes, you would use Findrecord and specify a WHERE clause (without the
WHERE keyword) as a parameter. Assuming the field in the table is called
'unique_record_number' and the record you want to return to is still
selected when the button is pressed, the code to requery a form and
return to the last record might look something like this :

Private Sub MyCommandButton_Click()
Dim lngID As Long
Dim rstData As Recordset

lngID = Nz(unique_record_number, 0) 'Save the ID
of the current record
Me.Requery 'Requery the form
Set rstData = Me.Recordset.Clone 'Create a copy
of the recordset
rstData.FindFirst "unique_record_number = " & lngID 'Locate the
old record
If Not rstData.EOF Then 'If the old ID
was found
Me.Bookmark = rstData.Bookmark ' Then set
the form's current record to the one found in the copy
Else 'Else tell the
user
MsgBox "The ID no longer exists in the recordset", vbInformation
End If
rstData.Close
Set rstData = Nothing
End If


HTH


Jan T

FireyColin

unread,
Feb 3, 2012, 6:30:16 AM2/3/12
to
THanks Christian and Jan tried both of those options but neither
worked.

Patrick Finucane

unread,
Feb 3, 2012, 2:52:16 PM2/3/12
to
> worked.- Hide quoted text -
>
> - Show quoted text -

I thought I replied ealier. My response is probably floating between
a satellite and earth. Anyway...try
Not rstdata.NoMatch
instead of
Not rstdata.EOF

FireyColin

unread,
Feb 6, 2012, 4:55:53 AM2/6/12
to
Thanks Patrick and Jan
0 new messages