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

Dynamically change subform 1

Status
Not open for further replies.

dcurtis

Technical User
May 1, 2003
273
0
0
US
I have searched the posts and have not found an answer to my particular problem.

I have several subforms on a form. For performance reasons I would like to have one unbound subform control that I can change the source of with the click of a button (well, really several buttons). I don't want to put all the subforms on the form and use the visible property since they would all load with the form.

I tried playing with the .RecordSource property but can't make it work.

TIA for any help.
 
Let's say you have an option group with the following choices/values

Employees: value = 1
Customers: Value = 2

and an unbound subform named something like subfrmDynamic, and you have subforms named Employees and Customers that you want to display in the unbound subform.

In the AfterUpdate event of your option group, use code like this:

Code:
Private Sub optgrpSourceSelection_AfterUpdate()

    Select Case optgrpSourceSelection.Value
        Case 1
            Me.subfrmDynamic.SourceObject = "Employees"
        Case 2
            Me.subfrmDynamic.SourceObject = "Customers"
    End Select
End Sub

There are potential problems like you unbound subform being smaller than the subforms it will be displaying, in which case your user will have to use horizontal/vertical scroll bars to get around.

Hope this helps.

Tom

Live once die twice; live twice die once.
 
How are ya dcurtis . . .

I've been down this road . . .

Eaisest is as follows:
[ol][li]In design view set all the visible property of all subforms to No! . . . and set recordsource for the same to [blue]""[/blue] nothing. This leaves you with a mainform that opens with no subforms! . . . [blue]AKA no performance hits![/blue][/li]
[li]Now if by default you have certain subforms that need to open, then in the [blue]OnLoad[/blue] event of the mainform, make it so:
Code:
[blue]   Me!MainFormName!subFormName.Form.RecordSource = YourRecordSource
   Me!MainFormName!subFormName.Form.Visible = true
[/blue]
[/loi][/ol]

Calvin.gif
See Ya! . . . . . .
 
dcurtis . . .

Disregard my last post . . . hit submit too soon!

Calvin.gif
See Ya! . . . . . .
 
Thomas -

With a little modification your code worked perfectly. Thanks. All I did was change from an option box to individual buttons, using the code in the OnClick.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top