Link to home
Start Free TrialLog in
Avatar of Karl001
Karl001Flag for Canada

asked on

Return on a specific record - Access Form

Hi,

On a main form, I have a list of records, with a details button on each row.

When I click on the details button, a new form is opened with details of the selected record

When I close the details form, I would like to go back on the record previously selected.

Currently, I return on  the top of the records list in the main form.
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

that is a normal behavior when you Requery the Form, the pointer goes to the first record..

'save the recordid in a variable

dim varID
varID = me.recordId
me.requery

'after the requery, find the record using


me.recordsetclone.findfirst "[recordID]= " & varID
if not me.recordsetclone.nomatch then
me.bookmark=me.recordsetclone.bookmark
end if



ASKER CERTIFIED SOLUTION
Avatar of datAdrenaline
datAdrenaline
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Karl001

ASKER

To be sure

Dim varId is a module variable

Code:
       varId = me.recordId
is  in click event (detail button)

Code:
      me.recordsetclone.findfirst "[recordID]= " & varID
      if not me.recordsetclone.nomatch then
           me.bookmark=me.recordsetclone.bookmark
      end if
is in Form_Current event

SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Karl001

ASKER

Solution used:

In details Form, on click event (closing button)

Private Sub btnClose_Click()

   Dim strActiveRecord As String

   strActiveRecord = "[trainingNo]=  '" & Me.txtTrainingNo & _
                                   " ' AND [departmentId]=" & Me.lstDepartment
    DoCmd.Close
   
   Forms. mainForm.Requery
   Forms. mainForm.Recordset.FindFirst strActiveRecord

End sub