Combo List to open different subforms

  • Thread starter Thread starter Todd
  • Start date Start date
T

Todd

I have a combo box bound to a table. What I would like
to be able to do is when a user selects a record from the
combo box, I would like to open a subform with further
information to ask. The records in the combo box are all
different reports that the user can print. When they
select a report, it would need further information that
are individual to the report such as date range,
individual record, etc...
Any help that can be provided would be greatly appreciated
 
Todd,

I'll assume you already have the subforms created (Subform1, Subform2,
etc.). On the form containing your combo box, add an unbound (no
SourceObject) subform control (I'll name it "subDynamic"). Then, in the
AfterUpdate property of your combo box, do something like this:
-----------------------------------
Dim strSubFormName As String
SELECT CASE cboReports

CASE 1 'Report 1
strSubFormName = "Subform1"
CASE 1 'Report2
strSubFormName = "Subform2"

END SELECT

Me.subDynamic.SourceObject = strSubformName
-----------------------------------

Note that all the subforms need to fit into the size you created for your
default subform control or you'll need to deal with dynamically resizing the
control.

Hope this helps. Reid.
 
Thank you for the suggestion.
I tried this last night and was not successful.
When I select any of the options in my combo box, nothing
is displayed in my subform. It is just a white box. Any
Ideas on this one?
I did put the code in as you suggested under the After
Update section.
 
Hmmm. I tested this with an Access 2000 form and it worked fine for me. The
white box denotes an unbound subform and is what you want initially. As a
test, add a command button to your form with the following single line of
code in the OnClick event, replacing "mySubformName" with the name of an
actual subform you want to use:

Me.subDynamic.SourceObject = "mySubformName"

When you click the button, your subform should display. If this doesn't
work, I'm not sure what to say. If this does work, then something is wrong
with your other combo box code.

Note that unless you use these subforms for other purposes than on these
forms, I wouldn't tend to use this method. I'd use a tab control and simply
make visible a single tab corresponding to the combo box selection. That way
you only have one form object to deal with and not a bunch of subforms.

Let me know how it goes. Thanks.
(e-mail address removed)
 
Back
Top