Solved

Return on a specific record - Access Form

Posted on 2011-09-30
6
290 Views
Last Modified: 2012-06-22
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.
0
Comment
Question by:Karl001
  • 2
  • 2
  • 2
6 Comments
 
LVL 119

Expert Comment

by:Rey Obrero
Comment Utility
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



0
 
LVL 11

Accepted Solution

by:
datAdrenaline earned 500 total points
Comment Utility
Since you are likely not having to worry with any deletions, I would consider going a little "lower level" than caps suggestion (assumption is the the pk field is an autonumber and is named RecordId).

Dim lngId As Long
lngId = Me.RecordId

Me.Requery

Me.Recordset.FindFirst "[RecordId]=" & lngId

{note: definately not indicating there is anything incorrect with caps suggestion!}
0
 

Author Comment

by:Karl001
Comment Utility
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

0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 11

Assisted Solution

by:datAdrenaline
datAdrenaline earned 500 total points
Comment Utility
Not really ... the key is this ... When and How to you tell the main form to Requery?  Do you have code in the Detail form that requeries the Main form? or do you have an event that is triggered when the main form recieves the focus again?

Wherever that call to .Requey exists, you need to surround that call with a way to store the value of the current record (I would recommend a procedure level variable, not a module level variable), then the .Requery is called, then you perform the .Find.
0
 

Author Closing Comment

by:Karl001
Comment Utility
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
0
 
LVL 119

Expert Comment

by:Rey Obrero
Comment Utility
? :-(
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now