Loading un unloading subforms

NigelShaw

Registered User.
Local time
Today, 18:59
Joined
Jan 11, 2008
Messages
1,572
Hi,

what is the best way to load or unload subforms? currently, i have the subforms within my form and code will change it visible and invisible but it would be better i think if they could be loaded or unloaded as i iahve existing code in the forms that all needs to be written.
( i originally had the subforms as separate forms that opened as a single form ).

can you load / unload subforms on a form as normal forms?



regs,

NS
 
You set the rowsource property when you need it. So, you can start it off without a rowsource and then use something like:

Code:
Dim strSQL As String

strSQL = "SELECT * FROM MyTable"
Me.YourSubformCONTAINERNameHere.Form.Rowsource = strSQL

where YourSubformCONTAINERNameHere refers to the control on the main form which houses the subform. It CAN be the same name as the subform but it isn't always, so you need to make sure to use the container name instead of the subform name. And, the rest of it is as shown (for example the .FORM. does not mean to put the form name there, it means exactly that - .FORM. as written.

You can also set the source object of the subform container if you prefer. In other words, you can assign the subform to the container at various times:

Code:
Me.YourSubformContainerNameHere.SourceObject = "YourSubFormNameHere
 
Hi Bob,

thats great. i will have a look and post my findings.

many thanks,

NS
 
on some projects i have simply put one subform object on a form. when i want to display a different form in the subform change the sourceobject property via vba:

subform1.sourceobject = "formname"

the form that is currently loaded into the subform will fire its close routine and close, the form you have selected to open will fire its open routine and then display in the subform control.
 
on some projects i have simply put one subform object on a form. when i want to display a different form in the subform change the sourceobject property via vba:

subform1.sourceobject = "formname"

the form that is currently loaded into the subform will fire its close routine and close, the form you have selected to open will fire its open routine and then display in the subform control.

Isn't that exactly what I had written too?
You can also set the source object of the subform container if you prefer. In other words, you can assign the subform to the container at various times:


Code:
Code:
Me.YourSubformContainerNameHere.SourceObject = "YourSubFormNameHere"
 
Ha ha sorry Bob yeah:). Was flicking through quickly while at work and only read Nigel's question and jumped straight into quick reply.
 
Hi Guys,

just to make sure i understand you correctly, i place a blank subform on the main form. then with vb, set the object source to another form. this will then show the items from that form. when i need to change the form, change the object source again to the new form. this will close the other form previously in the subform.

am i right?


thanks,

NS
 
Hi Again,

i just tried that and it works great :)

so, to make sure i have the correct procedures working when the forms close, do i place code in the on close of the closing form?

( i already have my forms created as pop up forms but would rather them be integrated into te main form. using your method, i can open the form within the subform. i currently have code written on the existing pop up forms close buttons to check if fields are dirty. then if they are the code does its thing. would i place this code into the on close instead )?


many thanks for your help.


Nigel
 
Hi Guys,

to advance on this, the subform that is opened with this method needs to be linked to the data of the person on the mainform so i would need a criteria link. using bobs code, would it be something like-

Dim strSQL As String

strSQL = "SELECT * FROM MyTable * WHERE Field"
Me.YourSubformCONTAINERNameHere.Form.Rowsource = strSQL

Though i am trying to avoid tables. i am trying to open my already made forms as subforms with links to the main form. every form that opens is linked by ContractorID


Thanks,

Nigel
 
Last edited:

Users who are viewing this thread

Back
Top Bottom