Locate record in a subform

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?
 
D

Dale Fye

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top