change subform programatically

T

Tara

I have a form that currently has 4 subforms. It makes the form way too
cluttered. What I would like to do is create one subform and have the data,
controls, etc change through code based on which command button is clicked.
I know this can be done, but i have no idea where or how to start!

Any help is appreciated.
 
G

Golfinray

Build a new form called "Form Select" or something like that. Make "Form
Select your subform on the mainform. Put 4 command buttons on the Form Select
form. Make the command buttons open the four forms. Use the wizard to do that
for you. The command button wizard will build the code for you.
 
G

George Nicholson

Where sctlSubformContainer is the name of the subform *control* on your
form, not the name of the subform itself. (If you drag & drop a subform onto
a form, the wizard will probably give the containing control the same name
as the subform. This can be very confusing. Change the name of the
container.)


Sub cmdShowNamesInSubform_Click()
Me.sctlSubformContainer.SourceObject = "frmNameSubform"
End Sub

Sub cmdShowInvoicesInSubform_Click()
Me.sctlSubformContainer.SourceObject = "frmInvoiceSubform"
Me.sctlSubFormContainer.Form.Filter = "[InvoiceNo] = " & me.txtInvoiceNo
Me.sctlSubFormContainer.Form.FilterOn = True
End Sub
 
T

Tara

I'm trying that now actually, and it's not working. The parent form opens
with the primary subform already visible. For some reason, when I click on
another tab to open a different subform, the top portion of my main form
disappears. I'm not sure why, since all the subforms are sized the same,
etc. I'm going to investigate a bit more and see if I can figure out what's
going on. If I can't get it fixed, I'll try George's idea.
 
T

Tara

Thanks George! I'll try your approach and see what happens.

George Nicholson said:
Where sctlSubformContainer is the name of the subform *control* on your
form, not the name of the subform itself. (If you drag & drop a subform onto
a form, the wizard will probably give the containing control the same name
as the subform. This can be very confusing. Change the name of the
container.)


Sub cmdShowNamesInSubform_Click()
Me.sctlSubformContainer.SourceObject = "frmNameSubform"
End Sub

Sub cmdShowInvoicesInSubform_Click()
Me.sctlSubformContainer.SourceObject = "frmInvoiceSubform"
Me.sctlSubFormContainer.Form.Filter = "[InvoiceNo] = " & me.txtInvoiceNo
Me.sctlSubFormContainer.Form.FilterOn = True
End Sub

--
HTH,
George


Tara said:
I have a form that currently has 4 subforms. It makes the form way too
cluttered. What I would like to do is create one subform and have the
data,
controls, etc change through code based on which command button is
clicked.
I know this can be done, but i have no idea where or how to start!

Any help is appreciated.
 

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