Instance of form as a sub-form? (2 Viewers)

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 13:45
Joined
Jul 9, 2003
Messages
17,517
I want to show an instance of a form in a sub-form window on my main form. But everything I try fails. :(


Any help or advice would be appreciated.


Here is my code…

Code:
Public Sub CopyOrder2() ' Initiates an instance of the form "Form_Orders"

Dim frmOrders3 As Form

'(I tried it as Static as well) 'Static frmOrders3 As Form_Orders
Set frmOrders3 = New Form_Orders

With frmOrders3
  .Visible = True
  .Detail.BackColor = vbWhite
  .cmdCopyOrder.Visible = False
  
End With
   
End Sub



Private Sub Command2_Click()
On Error GoTo Err_Command2_Click

   CopyOrder2  ' Runs the code to create an instance of the form

Let subOrders.SourceObject = "frmOrders3" 'Set the sub report window to the new instance of the form


Exit_Command2_Click:
    Exit Sub

Err_Command2_Click:
    MsgBox Err.Description
    Resume Exit_Command2_Click
    
End Sub
 
A subform is simply a control on another form. To add a subform to a mainform either choose the subform control from the toolbox or drag the name of a form from the form window onto the open main form. Access will make it a subform.
 
I am OK with using a form in a subform control, where I am having problems is using an “instance” of a form in a sub form control.

I have one form which I want to display four times as a subform on the main form. I could copy the form four times and then change its record source to four different queries, but I thought the more professional approach would be to have one form and then use “instances” of that form and set the record source in code.

But everything I try to load an “instance” of the forum into the subform control fails. I wondered if I was missing something obvious (as usual) or, is it not possible?

I thought I may have to add the “instance” to the forms collection, but I read in the help files that you are not allowed to add or delete forms from the forms collection. This is probably the wrong tree, but I’m willing to bark at anything at the moment!
 
Just to clarify, you want the form to be displayed four times on your main form, all with different recordsources?

I am fairly sure that an 'instance' of a form can only be used on the parent form, not a subform of the parent.

As you are using the form as a subform, you must place 4 separate subforms on the main form. This does not mean you need to create 4 copies of the form in the Db, just drag the one form onto your main form 4 times, change the names and set the recordsource for them dynamically on the Form_Current event.
 
I was looking back through my posting history and found this post --- and this is where the idea of adding multiple subforms eventually ended up !!!

 
Last edited:
This question makes no sense. No only is it possible, but requires no code. Every form in a subform is an instance of that forms class. So of course you can have as many form instances as you want. So if you add four subform controls and they all have the same source object, it creates four unique instances of that form. You can change every single run time property you want. Change the recordsource, change the appearance, hide and show controls. You can modify the four instances in a way that they would not even look similar.
 

Users who are viewing this thread

Back
Top Bottom