Locate record in a subform

  • Thread starter Thread starter DianePDavies
  • Start date Start date
D

DianePDavies

I have made a form to edit records. My main form has fields to enter/modify
data in the current record.

For the overview I have inserted a subform with a continuous form showing
the same records in a list - but only showing the first line of each record.
This subform is used to scroll down the list of records - i.e. to navigate.
The current record of the subform is then used to position the record of the
main form - i.e. display the full details of the current record.

Now - when I insert a new record in the main form - when done I requery the
subform to get that to include the new record. But then I also want it to
make the just inserted record the current one - and have a field in the new
record be the active field in my scroll-list (the subform).

I have tried the following - "QuestionList" being the subform and "QID"
being the key of the record:

Private Sub Form_AfterInsert()
Dim rs As Object
Me.QuestionList.Requery
Set rs = Me.QuestionList.Form.Recordset.Clone
rs.FindFirst "[QID] = " & Me.QID
If Not rs.EOF Then Me.QuestionList.Form.Bookmark = rs.Bookmark
Me.QuestionList.SetFocus
End Sub

But it doesn't work. I get the last record in my subform - but the current
record is the first one in the list.

Any suggestions?
 
Diane

After your Find first line, you need to check to see if there was a match,
not EOF. Try:

if not rs.nomatch then me.questionlist.form.bookmark = rs.bookmark

You might also want to consider setting the focus to a specific control in
the subform. I usually have a textbox (txtDummy) with zero width as the
furthest left control on my continuous subforms. Something like:

me.QuestionList.Form.txtDummy.SetFocus
 
Back
Top