getting back to a record

  • Thread starter Thread starter Bill H.
  • Start date Start date
B

Bill H.

I use a command button on a subform to add a record to the query suppoting
the parent form.

I don't see that new record unless I requery the parent form. But that
brings me back to the first record. How do I get back to the record I just
added? I need to edit some more fields.

Thx
 
Bill H. said:
I use a command button on a subform to add a record to the query
suppoting the parent form.

I don't see that new record unless I requery the parent form. But
that brings me back to the first record. How do I get back to the
record I just added? I need to edit some more fields.

To get to the record you just added after requerying the form, you're
going to have to know information that uniquely identifies that record,
such as its primary key value. If you know that, you can use code along
these lines.

'----- start of example code -----

Dim frm As Access.Form

Set frm = Me.Parent ' code is running on subform

frm.Requery

With frm.RecordsetClone
.FindFirst "IDField = " & IDofAddedRecord
If Not.NoMatch Then
frm.Bookmark = .Bookmark
End If
End With

Set frm = Nothing

'----- end of example code -----
 
Assuming of course that the underlying recordset is not SORTED the
suggestion will work.
DoCmd.GoToRecord acDataForm, [formName], acLast
I use a command button on a subform to add a record to the query
suppoting
the parent form.

I don't see that new record unless I requery the parent form. But that
brings me back to the first record. How do I get back to the record I
just
added? I need to edit some more fields.

Thx
 
David C. Holley said:
Assuming of course that the underlying recordset is not SORTED the
suggestion will work.
DoCmd.GoToRecord acDataForm, [formName], acLast

I wouldn't recommend that. As you are obviously aware, if the form's
recordset is sorted, the record that was added may not be the last
record on the form, after requerying. But if the form's recordset is
*not* sorted, the record that was added may *still* not be the form's
last record. The order of records in an unsorted recordset is
arbitrary. In simple cases, Access will usually return records in
primary-key order, so if you are adding records with consecutive
autonumber keys, your suggestion will likely work. But if the primary
key doesn't naturally sort to the end, requerying the form is not going
to return that record at the end of the recordset. And if the table has
no primary key, or if the form's recordsource is a complex query, Access
will return the records in whatever order it (or rather, the Jet
database engine) finds most convenient.
 
Well, no joy yet.

I modified the syntax a bit because the unique field I want to use is text,
and I presumed your example anticipated a numeric value.

.FindFirst "SessionRefID = '" & Me.SessionRefID & "'"

I presume it is supposed to get inside the if statement, and it does not.

:-(

--Bill
 
oopps, my fault.

I cleared out the fields above the place where I inserted your code.

Seems OK now.

:-)

--Bill
 
Back
Top