简体   繁体   中英

Open multiple forms issue in Access

I got query to make some modification that enable user to open multiple instances of the form when they do search data. I got manage to create a new module following Allen Browne guide and now I can open multiple instances of the spreadsheet which is good step forward but I cannot find solution how I can open that specific form.

In module I have got following code:

Public clnClient As New Collection    'Instances of frmClient.
Function OpenAClient()
    'Purpose:    Open an independent instance of form frmClient.
    Dim frm As Form

    'Open a new instance, show it, and set a caption.
    Set frm = New Form_SurgeriesForm
    frm.Visible = True
    frm.Caption = frm.Hwnd & ", opened " & Now()

    'Append it to our collection.
    clnClient.Add Item:=frm, Key:=CStr(frm.Hwnd)


    Set frm = Nothing
End Function

And under my button I replaced bit:

DoCmd.OpenForm "SurgeriesForm", acNormal
Forms!SurgeriesForm.Requery

.. and usef following code:

ModuleInstances.OpenAClient

I recon I need to add / change somehow the code below to be able to open multiple instances but do not have idea how to do it.

DoCmd.OpenForm "SurgeriesForm", acNormal
Forms!SurgeriesForm.Requery

I appreciate for any help with this as i got stuck and do not know how I can achieve this.

I think this is what you want?...

With the button on your SurgeriesForm add this code to the On Click event to open a new instance of the form:

Private Sub Command8_Click()
    OpenAClient
End Sub

This will create a new instance of the form each time you click the button.

Next, add a blank combo-box to the form and change it's Row Source Type to Value List .
Add this code to the form:

Private Sub Combo9_GotFocus()
    Dim frm As Variant

    Combo9.RowSource = ""

    For Each frm In clnClient
        Combo9.AddItem frm.Caption
    Next frm
End Sub

Now, when you click the drop-down it will list each form that you have created an instance of.

Finally, add this code to the form:

Private Sub Combo9_AfterUpdate()
    clnClient(Combo9.Value).SetFocus
End Sub

Now, selecting a form name from the combo-box will move the focus to that form.

NB: You'll need to update the name of the controls to match yours.
NB2: Remember to open the first form using OpenAClient or it won't get listed in the combobox (as it's not in the collection).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM