How to create a Sub form Dynamicly

itmasterw

Registered User.
Local time
Today, 01:27
Joined
Oct 31, 2005
Messages
45
Hi,

I have been looking every where and I cannot find this.

I need to create through code a subform on a main form. We have a main form that has textboxes that get populated with data on the top of the form and on the bottom of the form they want to be able to hit button and bring in any one of some 50 - 60 subforms that we have. I cannot put them all on this one form and make them visible and invisible because 10 it would be a mess to have all that and 2) they would all load and really slow down the system; they have this in a tab form and because it all loads at once it is really solw.

So I am looking for how to create a subform an a with VBA code.

Thank you
 
Rather than create a subform maybe you can just switch the source object of one subform control. In the attached database this is demonstrated on frmMain which has buttons that load either Form1 or Form2 two into the subform control. Usually the subform control takes on the name of the form put in it but it this case I renamed it to "SubFormControl" to distinguish it. The following code switches the forms.

Code:
Private Sub LoadForm1_Click()
Me.SubFormControl.SourceObject = "Form1"
End Sub

Private Sub LoadForm2_Click()
Me.SubFormControl.SourceObject = "Form2"
End Sub
 

Attachments

Hi this would be great but in MS access 2010 it is telling me that this does not exist "SourceObject " any thoughts as to what I can do?
 
SourceObject is a property of the subform control. Sounds like you are trying to apply to a different type of control
 
Hi this would be great but in MS access 2010 it is telling me that this does not exist "SourceObject " any thoughts as to what I can do?

Are you saying the database I uploaded doesn't work in Access 2010?
 
Hi,
Thank you for your reply. Unfortunately I cannot download your app here at work.
But I tried putting you code in the click event of a button that I am going to use to load the form and I got that message.
This is my code:
Code:
   Private Sub CmdInfo1_Click()
Me.SubFormControl.SourceObject = "frm_sub_Info1"
  
End Sub

I also tried putting it in here

Code:
   Private Sub SubFormControl_Click()
Me.SubFormControl.SourceObject = "frm_sub_Info1"  
End Sub


Thank you
 
Last edited:
If you have the already have the data on tabs - convert each tabs data to a subform and only load the subform when the tab is selected.
This removes unnecessary data being loaded until it is needed, and because each subform only has a limited amount of data they generally load quite quickly.
 
Below is a screen shot of what the form in that database looks like. Note that the subform control is named SubFormControl. In your code you need to change it to the name of your subform control.

attachment.php
 

Attachments

  • FormInDesignView.jpg
    FormInDesignView.jpg
    99.9 KB · Views: 147
thank you but I really would rather do something in dynamically loading subforms.
Thank you
 
Hi,
So now I have this is this what you have?
Code:
Private Sub SubFormControl_Click()
Me.SubFormControl.Child1 = "frm_sub_Info1"
End Sub

because it is coming back Method or data member not found

Thank you
 
What's Child1? In the form with the subform control you should have.

Code:
Me.TheNameOfYourSubFormControl.SourceObject = "frm_sub_Info1"

if "frm_sub_Info1" is the name of the form you want to load.

After you type Me. the name of you subform control should be in the drop down provided by Intellisense and after you type Me.TheNameOfYourSubFormControl. you should see SourceObject in the drop down.
 
Thanks for being patient with me, I got it to work.
Thanks for all your help this is great.
 

Users who are viewing this thread

Back
Top Bottom