Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Form instance

Status
Not open for further replies.

citychap26

Programmer
Sep 19, 2004
144
GB
Hi Guys,

Sorry if this has been answered before, I have searched and the sad thing is I have done it before !!

I want to open multiple instances of a form. I know that I have can use the following :

Code:
    Dim frm As Form
    
    Set frm = New Form_frm_FULL_RECORD
    
    frm.Visible = True
   ' frm.OpenArgs = Me.Child0.Form.UNIQUE_KEY.Value
    frm.RecordSource = "select * from qry_EXCLUDE_TRANSACTIONS where UNIQUE_KEY = '" & Me.Child0.Form.UNIQUE_KEY.Value & "'"

    
    'frmOpen Me.Form.Name, "frm_FULL_RECORD", Me.Child0.Form.UNIQUE_KEY.Value, False

    Debug.Print "Opening: " & Me.Child0.Form.UNIQUE_KEY.Value
[code/]

however the form just flashes up and goes. 

I seem to remember something about holding a global variable or a collection ??? 

Please help as I'm going mad.

Cheers

SK
 
Hi All,

Need to add the form to a collection which has been defined as a public var.

Cheers

SK
 
Using a collection is the best ways to manage form instances but simply declaring
public frm as Form_frm_FULL_RECORD

and then in the module
Set frm = New Form_frm_FULL_RECORD

would solve your problem. Currently "frm" goes out of scope as soon as you open it and the module complets.
 
citychap26,
Global yes, Collection yes. To build on what MajP is saying, your new from disapears when the variable ([tt]frm[/tt]) goes out of scope, which I suspect is in your procedure.

A Global Collection will allow you to hold multiple forms open for as long as the parent ([tt]Me[/tt]) is open. There are a couple of moving pieces so I included the 'whole' form module.

Code:
Option Compare Database
Option Explicit

Private frmsSpawned As Collection

Private Sub Command0_Click()
  Dim frmSpawned As New Form_frm_FULL_RECORD
  frmSpawned.Filter = "UNIQUE_KEY = '" & Me.Child0.Form.UNIQUE_KEY.Value & "'"
  frmSpawned.FilterOn = True
  frmSpawned.Visible = True
  frmsSpawned.Add frmSpawned
  Set frmSpawned = Nothing
End Sub

Private Sub Form_Open(Cancel As Integer)
  Set frmsSpawned = New Collection
End Sub

Private Sub Form_Close()
  On Error Resume Next
  While frmsSpawned.Count > 0
    frmsSpawned.Remove 1
  Wend
  Set frmsSpawned = Nothing
End Sub

Hope this helps,
CMP

[small]For the best results do what I'm thinking, not what I'm saying.[/small]
(GMT-07:00) Mountain Time (US & Canada)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top