Dynamic Subform Creation

Randomblink

The Irreverent Reverend
Local time
Today, 16:11
Joined
Jul 23, 2001
Messages
279
I have a form that has MULTIPLE Subforms that COULD be necessary...

Now I realize I could open each subform using a button on the main form...but I don't wanna...

I also realize I could create MULTIPLE subforms on the main form, but that slows everything down when a form has to load up to seven subforms...(this was the previous way I did this form)

I am re-writing and want to click a button...
And the EMPTY subform control connects to the correct subform based on the button clicked...
However, I can't seem to make this happen for the life of me...

Does someone have any idea why?
I get errors that state you can only create subforms in Design mode of a form? Others that say this Object cannot be created in VIsual Basic...? I just keep getting confused...

Here is the basic code I was attempting to use:

Private Sub btn_ViewSponsorSubfrm_Click()
Dim newsub As New SubForm
With newsub
.Left = 0.9792
.Top = 2.3542
.Height = 5760
.Width = 4320
.SourceObject = "subfrmMed_SponsorBasicListing"
.LinkMasterFields = "Proj_ID"
.LinkChildFields = "Proj_ID"
End With
Me.Refresh
End Sub


If you can help me, I would be grateful...
 
Indeed you do not want to create a new form, just to switch between already existing one. I would put a 'default' subform (eventually invisible untill the user selects one), then just switch its ObjectSource depending on the user's choice

You would then only need something like
Code:
Private Sub btn_ViewSponsorSubfrm_Click() 
Dim frmSwitchForm As Form

Set frmSwitchForm = Me!YourSubFormName
With frmSwitchForm 
.Left = 0.9792 
.Top = 2.3542 
.Height = 5760 
.Width = 4320 
.SourceObject = "subfrmMed_SponsorBasicListing" 
.LinkMasterFields = "Proj_ID" 
.LinkChildFields = "Proj_ID" 
End With 
Me.Refresh 
End Sub
 
works fine for me

Hi,
I hav ejust looked on this forum for a solution to the a similar problem that Randonblink reported, and the solution provided by Alexandre was just what I was looking for.

Many thanks guys.

Peter
 

Users who are viewing this thread

Back
Top Bottom