Programming a Button to open tabform on specific tab

  • Thread starter Thread starter Digital Carnage
  • Start date Start date
D

Digital Carnage

Hi folks,
I just read a post reply from Sandra Daigle about programming tabcontrol
so I'm not sure if I'm asking the same question all over again. I have a
main administrative form (frmAdminMain) that has two buttons specifically.
One button is an "Add New Employee & Vehicles" and the second button is
"Add New Vehicles to existing employees". Each button takes you to a
tabular form called "MfrmEmployees" which has 3 tabs. The first tab just
contains basic employee information. The second tab uses a subform to add
new vehicles. The third tab uses a subform to edit existing vehicles. All
of this works great and the data is accurate! (Yeah!). But, can I program
the add button to go right to the second tab called "Add Vehicle(s)" and
program the edit button to go to the third tab called "Edit Vehicle(s)"?
I'm pretty new to this aspect of things so an example would be extremely
helpful. Thanks Rich
 
Hi Rich,

It is basically the same concept - you just need to use the full reference
to the called form ("MfrmEmployees").

I'm guessing that frmAdminMain allows you to select an existing employee so
that when the second form is opened, that employee's record is showing. With
this in mind, I'll use the WhereCondition parameter of Docmd.openform - here
is some air code for your second button click event (replace "myTabCtl" with
the name of your tab control):

docmd.openform "MfrmEmployees",,,"EmployeeId=" & me.employeeid
forms!MfrmEmployees!myTabCtl=1


** or better yet, using my tip about indirectly referencing the page number
to avoid the hardcoded pageindex you would use the following, replacing
'pgAddVehicle' with the name of the page that you want to have the focus:

docmd.openform "MfrmEmployees",,,"EmployeeId=" & me.employeeid
forms!MfrmEmployees!myTabCtl=forms!MfrmEmployees!myTabCtl.pages("pgAddVehicl
e").pageindex
 
Sandra,
Thanks very much for this! I've beaten my head repeated on my monitor
about this. You can feel that you're so close sometimes with your code but
it just doesn't work the way you want. Your suggestion here should work
great. I'll give it a workover and reply back to the discussion group when
It works fully. Thanks Rich

Sandra Daigle said:
Hi Rich,

It is basically the same concept - you just need to use the full reference
to the called form ("MfrmEmployees").

I'm guessing that frmAdminMain allows you to select an existing employee so
that when the second form is opened, that employee's record is showing. With
this in mind, I'll use the WhereCondition parameter of Docmd.openform - here
is some air code for your second button click event (replace "myTabCtl" with
the name of your tab control):

docmd.openform "MfrmEmployees",,,"EmployeeId=" & me.employeeid
forms!MfrmEmployees!myTabCtl=1


** or better yet, using my tip about indirectly referencing the page number
to avoid the hardcoded pageindex you would use the following, replacing
'pgAddVehicle' with the name of the page that you want to have the focus:

docmd.openform "MfrmEmployees",,,"EmployeeId=" & me.employeeid
forms!MfrmEmployees!myTabCtl=forms!MfrmEmployees!myTabCtl.pages("pgAddVehicl
e").pageindex

--
Sandra Daigle
[Microsoft Access MVP]
For the benefit of others please post all replies to this newsgroup.


Digital said:
Hi folks,
I just read a post reply from Sandra Daigle about programming
tabcontrol so I'm not sure if I'm asking the same question all over
again. I have a main administrative form (frmAdminMain) that has two
buttons specifically. One button is an "Add New Employee & Vehicles"
and the second button is "Add New Vehicles to existing employees".
Each button takes you to a tabular form called "MfrmEmployees" which
has 3 tabs. The first tab just contains basic employee information.
The second tab uses a subform to add new vehicles. The third tab
uses a subform to edit existing vehicles. All of this works great
and the data is accurate! (Yeah!). But, can I program the add
button to go right to the second tab called "Add Vehicle(s)" and
program the edit button to go to the third tab called "Edit
Vehicle(s)"? I'm pretty new to this aspect of things so an example
would be extremely helpful. Thanks Rich
 
Back
Top