Link to home
Start Free TrialLog in
Avatar of Joy Gomez
Joy Gomez

asked on

GoToRecord moves to the bottom of form sometimes

Hello,

I have a form and subform.  After a requery, when I try to gotorecord in the subform, sometimes the record is in the bottom of the form.  Below is my code... how do I always have the record show up on the top.

Dim sf As Access.Form
        Set sf = Forms![F_Maint_Check_Main]![F_Maint_Check_Vol_SoftAR_EC_New].Form
           
            Dim value As Integer
            value = sf.CurrentRecord
                               
                sf.Requery
               
                   DoCmd.GoToRecord , , acGoTo, value
                       DoCmd.Close acForm, "F_Maint_Master_Edit_Button", acSaveYes
ASKER CERTIFIED SOLUTION
Avatar of Gustav Brock
Gustav Brock
Flag of Denmark 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 Joy Gomez
Joy Gomez

ASKER

Thanks for the comment... so is there any other option for me to always have the record show up on top of the form view?  I tried Bookmark, but that does not seem to be working.
Not that I know of.
There is no property that returns the relative position of a record in the form, only in the full recordset of the form (CurrentRecord).
Joy:  Don't be so hasty in settling for just one opinion.  It is possible to do.  In fact, not only can you get any record to appear as the 1st record at the top of a datasheet subform, but you can put it at the bottom if you want, or anywhere in-between!

All it requires is 5 additional lines of code in the procedure where you select your subform record.
Dim lngSubformHeight as Long
'GET the original height of the subform:
lngSubformHeight=me.subformcontrolnamehere.height
'SET the subform control's height to 1% (.01) of the original height:
me.subformcontrolnamehere.height=lngsubformheight*.01
'Move to the first record in the subform:
Me.subformcontrolnamehere.form.recordset.movefirst
….put your code to select your record here
'Now, set the height of your subform control back to its original value:
Me.subformcontrolnamehere.Height=lngSubformHeight

Open in new window


Your record should appear at the top of your subform.  The reason this works is because Access positions a record in a datasheet subform at the BOTTOM of the subform control - regardless of where the bottom is.  Resizing the subform control back to its original height exposes the records beneath the selected record WITHOUT moving the record's position relative to the top of the subform.
The attached access demo app demonstrates this and a lot more things you can do.

Note:  The technique for repositioning records in a form varies depending on what kind of form you have (continuous form or datasheet, etc.)
RepositionSubformDatasheetRecords.accdb
For those of you out there who are using a continuous subform, I've included a form in the demo app that positions any selected record as the 1st record in the subform viewing area.

Enjoy....
RepositionSubformRecords.accdb