Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Run a control on one subform from a button on another subform.

Status
Not open for further replies.

weightinwildcat

Programmer
May 11, 2010
84
US
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
 
The nice think to do to show your appreciation is to click on [blue]Greet Post [/blue]link in the helpful post.

Have fun.

---- Andy

There is a great need for a sarcasm font.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top