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_Butto n", acSaveYes
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]
Dim value As Integer
value = sf.CurrentRecord
sf.Requery
DoCmd.GoToRecord , , acGoTo, value
DoCmd.Close acForm, "F_Maint_Master_Edit_Butto
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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).
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.
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
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
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
Enjoy....
RepositionSubformRecords.accdb
ASKER