Hidden subform on a mainform.

Lifeseeker

Registered User.
Local time
Today, 14:35
Joined
Mar 18, 2011
Messages
273
Hello,

Just a exploring a concept here.

I have a main form which is full of controls with a subform at the bottom.

For ease of viewing, I would like to include another subform on the mainform, but keep it hidden until enabled. (saving space)

I'm thinking I should include a button and when the button is clicked, the subform rolls down or just opens in some way.

Is this possible at all in Access 2007?

Any comment much appreciated.
 
Yes it is possible. If both subforms is about the same size then you can create an emtpy subform conteiner that accomendates both in size and change the sourceobject in code.

Instead of a commandbutton you could use a Togglebutton instead and use the After_Update event of this button to switch subforms

Code:
Private Sub DefaultSubform()
    Me.sfrmConteiner.SourceObject = "subform1"
    Me.sfrmConteiner.LinkMasterFields = "PK"
    Me.sfrmConteiner.LinkChildFields = "FK"
End Sub

Code:
Private Sub AlternativeSubform()
    Me.sfrmConteiner.SourceObject = "subform2"
    Me.sfrmConteiner.LinkMasterFields = "PK"
    Me.sfrmConteiner.LinkChildFields = "FK"
End Sub

Then in your togglebuttons After_Update test the status and change forms:

Code:
Privat Sub tglSubform_AfterUpdate()
If Me.tglSubform = True Then
     AlternativeSubform
Else
     DefaultSubform
End If
End Sub

You should also use your mainform Loadevent to set the default subform:

Code:
Private Sub Form_OnLoad()
DefaultSubform
End Sub


JR
 
I got the impression that he wants 2 subforms on there at the same time, but one hidden and taking up no space by default.

This is also possible, but if you are looking to "save space" then you would need to also change the size of the subform control.

Even with a hidden subform control the mainform needs to be big enough to hold it. Therefore if you want the form to be small when the subform is hidden and only grow when it is visible you would also need to change the .Height property of the subform control (and possibly the main form) in the code too.
 
Might a Tab control be a better option?
 
Might a Tab control be a better option?

Good call.

The second tab could be hidden until needed, even the subform control's source object property could be null by default and only be loaded when that tab is displayed.

This would give the advantage of only taking the time to load the page & the data behind it if the user is enabling that subform. It's a good idea if the subform takes a long time to load and is not used frequently enough to justify slowing down the loading of the main form every time it is opened.
 
Hi, thanks for posting back.

I just tried it now, but when I clicked on the toggle button, there was an error saying sub or function not defined.

Error message is:

Private Sub Toggle21_AfterUpdate()
If Me.Toggle21 = True Then
AlternativeSubform
Else
defaultsubform
End If
End Sub



So I put the following code in the two subforms, respectively so that they can get called by the toggle button. Is it correct to do so?

Code:
Private Sub DefaultSubform() Me.sfrmConteiner.SourceObject = "subform1" Me.sfrmConteiner.LinkMasterFields = "PK" Me.sfrmConteiner.LinkChildFields = "FK"End Sub
Code:
Private Sub AlternativeSubform() Me.sfrmConteiner.SourceObject = "subform2" Me.sfrmConteiner.LinkMasterFields = "PK" Me.sfrmConteiner.LinkChildFields = "FK"End Sub



Yes it is possible. If both subforms is about the same size then you can create an emtpy subform conteiner that accomendates both in size and change the sourceobject in code.

Instead of a commandbutton you could use a Togglebutton instead and use the After_Update event of this button to switch subforms

Code:
Private Sub DefaultSubform()
    Me.sfrmConteiner.SourceObject = "subform1"
    Me.sfrmConteiner.LinkMasterFields = "PK"
    Me.sfrmConteiner.LinkChildFields = "FK"
End Sub

Code:
Private Sub AlternativeSubform()
    Me.sfrmConteiner.SourceObject = "subform2"
    Me.sfrmConteiner.LinkMasterFields = "PK"
    Me.sfrmConteiner.LinkChildFields = "FK"
End Sub

Then in your togglebuttons After_Update test the status and change forms:

Code:
Privat Sub tglSubform_AfterUpdate()
If Me.tglSubform = True Then
     AlternativeSubform
Else
     DefaultSubform
End If
End Sub

You should also use your mainform Loadevent to set the default subform:

Code:
Private Sub Form_OnLoad()
DefaultSubform
End Sub


JR
 
All the code needs to be on the main form.
Otherwise check the spelling of the function names.

I would also suggest you use a with block for tidiness

Code:
Private Sub DefaultSubform()
   With Me.sfrmConteiner
      .SourceObject = "subform1"
      .LinkMasterFields = "PK"
      .LinkChildFields = "FK"
   End With
End Sub
 
Hi, This is how I did it, I have a checkbox Sale

Code:
Private Sub Form_Current()

    Me.sfrmBuy.Visible = Nz(Me.Sale, False)
    Me.sfrmSales.Visible = Not Nz(Me.Sale, False)

Code:
Private Sub List210_Click()
On Error GoTo List210_Err
   
    
    Me.sfrmBuy.Visible = Nz(Me.Sale, False)
    Me.sfrmSales.Visible = Not Nz(Me.Sale, False)
    
DoCmd.SearchForRecord , "", acLast, "[ID] = " & Str(Nz(Screen.ActiveControl, 0))

List210_Exit:

    Exit Sub

List210_Err:
    MsgBox Error$
    Resume List210_Exit
End Sub

With thanks for the people that taught me here
 
All the code needs to be on the main form.
Otherwise check the spelling of the function names.

I would also suggest you use a with block for tidiness

Code:
Private Sub DefaultSubform()
   With Me.sfrmConteiner
      .SourceObject = "subform1"
      .LinkMasterFields = "PK"
      .LinkChildFields = "FK"
   End With
End Sub


Thank you very much
 

Users who are viewing this thread

Back
Top Bottom