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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Centralising code for multiple forms/subform to access

Status
Not open for further replies.

pmp1

Programmer
Jun 17, 2007
29
AU
Hi! I have created a record browsing window (data is displayed in datagrid in subform) which includes custom navigation buttons (first, next, last and previous). The custom buttons are disabled as appropriate (e.g. if at the first record, the GoToFirst and GoToPrevious buttons are disabled). All of this works perfectly.
My problem now is if the user clicks on a record directly in the datagrid (subform), say the third record down, the navigation buttons do not change their status - which I know I need to code.
The code that I have which works is in the BrowserForm module and the code needed to accommodate a user clicking on the datagrid needs to be in the subform.
I would like to only have the one peice of code to manage the navigation buttons (enable/disable) but do not where (which module) to store the code, the declaration I need to ensure any aspect of the application can use it or how to call it from the form/subform module.
I know it is a lot of work to write code for navigation buttons which is part of Access, however, I prefer my layout design to the inbuild one.
Could someone please explain what I need to do?
I hope I haven't confused you with my explaination.
Thanking you
Peter
 
If you can pick up a copy of the Access 200x Desktop Developers Handbook there is a very good example of this. This is the best Access programming book out there and you can pick up an old version (i.e 2002) for cheap on line. But to make this reusable on all of your forms, the controls and the code should be on their own unbound subform (a real small subform just the size of the controls). If the controls are on a subform then they can control any main form by using the "parent" property.

So for example maybe you have something like a txt box that shows the recordcount then on your navigation subform you would have something like

txtBoxCount = me.parent.recordsetclone.recordcount

Now on any main form that has this subform on it. You can from the main forms event just have something like

Private Form_Current()
'call some common procedure in the nav subform
'
Form_frmNavigation.procedureOnTheSubForm
end sub


So all code stays on the navigation subform. The main form only calls a procedure on the nav subform from the main forms onCurrent event.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top