Hi. I need to run a control on one subform from a button on another subform. Alternatively, I need to scroll through records on one subform by using a button on another subform. What VBA syntax should I use?
to refer to another subform from the current subform on the same mainform
Me.parent.OtherSubformControlName.Form
where "OtherSubformControlName" is the name of the other subform control and not necessarily the same name as the name of the form inside the subform control
the .Form then returns the form object within that control
There are several ways to scroll the records
You can use the docmd.gotorecord
or you can manipulate the recordset. In either case you should check if you try to go beyond the first or last record.
Code:
'To move next
Dim frm as access.form
Dim rs as dao.recordset
set frm = me.parent.othersubformcontrolname.form
set rs = frm.recordset
if rs.absoluteposition = rs.recordcount - 1 then
msgbox "last record"
else
rs.movenext
end if
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.