Subform switching using buttons

A

AccessNubee

DB/Form format: Access2002 running on Access2003.(yes I could convert it to
2003 if necessary)

I have a main form with control buttons on the left, subform on the right,
and the header will have the record selector to select the contact I want
to view. I want the subform swapable in the following manner:

The initial subform when the form opens will be populated with a GeneralInfo
subform.... showing a "to do list" ....

If I click the btnPayments button, the subform will be switched to the
payments subform. If I click the btnHistory button, it will show the History
subform. The page/main form doesn't change, just the subform based on the
CID(Primary Key) from the main form. I would prefer NOT to have these
just on tabs... I want to keep the db interface as clean as possible.

I suspect the OnClick event on the buttons will be where the code will go
but I have no idea what to do there. Somebody here suggested putting all
the subforms (8 in all) on the main form and hide them until you click the
button and Unhide them..... but wouldn't that be overkill? There's got to be
a better way.

Main form name: frmDataMaintainence
Subform name: subform_SwapMe
 
R

Rick Brandt

AccessNubee said:
DB/Form format: Access2002 running on Access2003.(yes I could convert
it to 2003 if necessary)

I have a main form with control buttons on the left, subform on the
right, and the header will have the record selector to select the
contact I want to view. I want the subform swapable in the
following manner:
The initial subform when the form opens will be populated with a
GeneralInfo subform.... showing a "to do list" ....

If I click the btnPayments button, the subform will be switched to the
payments subform. If I click the btnHistory button, it will show the
History subform. The page/main form doesn't change, just the subform
based on the CID(Primary Key) from the main form. I would prefer
NOT to have these just on tabs... I want to keep the db interface as
clean as possible.
I suspect the OnClick event on the buttons will be where the code
will go but I have no idea what to do there. Somebody here suggested
putting all the subforms (8 in all) on the main form and hide them
until you click the button and Unhide them..... but wouldn't that be
overkill? There's got to be a better way.

Main form name: frmDataMaintainence
Subform name: subform_SwapMe

If the forms you are using as subforms are all the same size (or close
enough) then you can use code to change the SourceObject property of a
single subform control.
 
A

AccessNubee

Rick Brandt said:
If the forms you are using as subforms are all the same size (or close
enough) then you can use code to change the SourceObject property of a
single subform control.

Yes, I've designed all the subforms to be the same size... just different
content...
I'm Very new to VBA :( but based on your suggestion, I searched and found
a sample code online and changed the form names to match mine...
I understand this statement.... thank god.... I tested it and this works!!!
:))))

Private Sub btnPayments_Click()
On Error GoTo Err_btnPayments_Click

'Swap the subform to the selected subform
Forms!frmDataMaintainence!subform_SwapMe.SourceObject =
"subform_Payments"

Exit_btnPayments_Click:
Exit Sub
Err_btnPayments_Click:
MsgBox Err.Description
Resume Exit_btnPayments_Click
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top