multiple instances of a form - selected records ms access 97

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • blad3runn69
    New Member
    • Jul 2007
    • 59

    multiple instances of a form - selected records ms access 97

    can anyone point me in the right direction re:
    handling multiple instances of a form opened from selected records in a search form

    I can get multiple forms thanks to allen browne & msdn
    howto get the new instance of the form to move to the record selected from the search form?

    thank you your help is muchly appreciated!
  • ADezii
    Recognized Expert Expert
    • Apr 2006
    • 8834

    #2
    Originally posted by blad3runn69
    can anyone point me in the right direction re:
    handling multiple instances of a form opened from selected records in a search form

    I can get multiple forms thanks to allen browne & msdn
    howto get the new instance of the form to move to the record selected from the search form?

    thank you your help is muchly appreciated!
    Just subscribing, when I get the chance I'll adapt Mr. Browne's code to your specifc needs, but first:
    1. What is the Name of your Search Form?
    2. What is the Name of the Form that will display the Search Results?
    3. What is the Record Source of this Display Form?
    4. What is the Name and Data Type of the Field you will be searching on?
    5. Is this Search Field the Primary Key or at least a Unique Index?
    6. Is there a Maximum number of Instances which should be created?
    7. Any other information you may think is relevant.

    Comment

    • blad3runn69
      New Member
      • Jul 2007
      • 59

      #3
      thanks for your help Adezii

      What is the Name of your Search Form?
      frmsearch
      frmsearch uses the logic based on this example

      What is the Name of the Form that will display the Search Results?
      frmsearch

      What is the Name and Data Type of the Field you will be searching on?
      Multi type filter (text/date/combo) - refer to example above

      What is the Record Source of this Display Form?
      tbltime

      Is this Search Field the Primary Key or at least a Unique Index?
      NO ^see above

      Applying filter to frmsearch user can then select a record from list of records displayed on frmsearch. This opens the chosen record in a new form - frmtime - for editing.

      Is there a Maximum number of Instances which should be created?
      NO

      Any other information you may think is relevant.

      quick background
      v.simple database
      search form shows filtered list
      user selects record from list for editing – opens new form to edit record
      I want to allow multiple instances of this edit form to allow multiple simultaneous edits.

      I can get multiple forms using this example

      I can get form to display selected record with DoCmd.Open ,,stLinkCriteri a method on the primary key using a modal form.

      what I am looking for is a way to combine these two things - multiple instances of frmtime which display the record selected from frmsearch

      thanks

      Comment

      • ADezii
        Recognized Expert Expert
        • Apr 2006
        • 8834

        #4
        Originally posted by blad3runn69
        thanks for your help Adezii

        What is the Name of your Search Form?
        frmsearch
        frmsearch uses the logic based on this example

        What is the Name of the Form that will display the Search Results?
        frmsearch

        What is the Name and Data Type of the Field you will be searching on?
        Multi type filter (text/date/combo) - refer to example above

        What is the Record Source of this Display Form?
        tbltime

        Is this Search Field the Primary Key or at least a Unique Index?
        NO ^see above

        Applying filter to frmsearch user can then select a record from list of records displayed on frmsearch. This opens the chosen record in a new form - frmtime - for editing.

        Is there a Maximum number of Instances which should be created?
        NO

        Any other information you may think is relevant.

        quick background
        v.simple database
        search form shows filtered list
        user selects record from list for editing – opens new form to edit record
        I want to allow multiple instances of this edit form to allow multiple simultaneous edits.

        I can get multiple forms using this example

        I can get form to display selected record with DoCmd.Open ,,stLinkCriteri a method on the primary key using a modal form.

        what I am looking for is a way to combine these two things - multiple instances of frmtime which display the record selected from frmsearch

        thanks
        As long as you are not in that great of a hurry, I'll see what I can do, but if you are in a rush, I'm sorry but I cannot be of much assistance to you. I'll hold off until I hear from you.

        Comment

        • blad3runn69
          New Member
          • Jul 2007
          • 59

          #5
          thanks again for your help ADezii, there is no rush. If I get anywhere I will also postback.
          cheers

          Comment

          • ADezii
            Recognized Expert Expert
            • Apr 2006
            • 8834

            #6
            Originally posted by blad3runn69
            thanks again for your help ADezii, there is no rush. If I get anywhere I will also postback.
            cheers
            Gotcha, blad3runn69 - see you around.

            Comment

            • blad3runn69
              New Member
              • Jul 2007
              • 59

              #7
              do u lose your newbie tag if you ask a ? which nobody here can answer (or criticise) easily... ?

              Comment

              • ADezii
                Recognized Expert Expert
                • Apr 2006
                • 8834

                #8
                Originally posted by blad3runn69
                do u lose your newbie tag if you ask a ? which nobody here can answer (or criticise) easily... ?
                I'll have something for you by the end of the day, maybe not the final solution right now, but something to point you in the right direction. BTW, I lost my Newbie Tag after 2,750 Posts. (LOL).

                Comment

                • ADezii
                  Recognized Expert Expert
                  • Apr 2006
                  • 8834

                  #9
                  Just giving you an Overview and Update of where I am at concerning your question. Creating Multiple Instances of a Form is a simple process which can be accomplished with as little as 3 lines of code. The difficulties arise when you attempt to differentiate between the Instances, and also when you try to manage them. Each Instance of a Form has exactly the same name, so you cannot refer to a specific Instance in the conventional manner of Forms!<Your Form Name>. You cannot also refer to a specific Instances within the context of the Forms Collection such as Forms(2), since the Indexes into the Forms Collection is constantly changing as Forms are opened or closed. There is also the problem of Closing a specific Instance of a Form as opposed to all Instances.

                  There is, however, light at the end of the tunnel. To effectively manage each Form Instance, we can create a Collection in a Standard Code Module. This Collection will contain the Form Instances and manage them: as each new Instance is opened it is added to the Collection, and as each Instance is closed it is removed from the Collection. To uniquely identify each Instance, we can use the value of its hWnd Property when it was created. This hWnd value is a unique Handle (LONG INTEGER) assigned to each Window by the Operating System, and is constant for the lifetime of the Window.

                  I have used a subset of Mr. Allen Browne's code as a base from which to work, I have made additions, deletions, and modifications to his code, as well as importing the Employees Table from the sample Northwind Database. The data contained within this Table will be the groundwork on demonstrating my solution as to how to open Multiple Instances of a Form based on different search criteria. When finished, I'll post some of my code illustrating these techniques as well as the Test Database itself. Be advised, this will only be a simple Template that hopefully, will provide the groundwork, or at least give you some direction, on how to accomplish what you are requesting.

                  P.S. - Allen Browne deserves the majority of the credit here. It is essentially his code and ideas which enabled me to arrive at a possible solution to your question.

                  Comment

                  • ADezii
                    Recognized Expert Expert
                    • Apr 2006
                    • 8834

                    #10
                    I think I have arrived at a workable solution, so what I'll do is post the relevant code only, and make the actual Test Database for this Thread available as an Attachment. I advise downloading the DB in order to get a much better idea of exactly what is going on.
                    [CODE=vb]'Create a Collection to hold all Form Instances
                    Public colInstance As New Collection 'Instances of frmInstance.[/CODE]
                    [CODE=vb]Private Sub cmdOpenAClient_ Click()
                    Dim Msg As String

                    'Check cboEmployees on frmSearch, if it has an Employee to search
                    'for, call the Function fOpenNewInstanc e(). cboEmployees consists of
                    '4 Columns, the first 3 of which are hidden
                    '[EmployeeID], UCase$([LastName]), [FirstName], and UCase$([LastName]) & ", " & [FirstName]
                    Msg = "You must first select an Employee to search for!"
                    If IsNull(Me![cboEmployees]) Then
                    MsgBox Msg, vbExclamation, "No Employee to Search For"
                    Me![cboEmployees].SetFocus
                    Me![cboEmployees].Dropdown
                    Else
                    Call fOpenNewInstanc e
                    End If
                    End Sub[/CODE]
                    [CODE=vb]Public Function fOpenNewInstanc e()
                    Dim frm As Form

                    'Open a new instance, show it, and set a caption.
                    Set frm = New Form_frmInstanc e
                    frm.Visible = True
                    'Set the Caption of the Form to "Search Results for LASTNAME, FirstName
                    frm.Caption = "Search Results for [" & Forms!frmSearch ![cboEmployees].Column(3) & "]"

                    'Read the value of the [EmployeeID] Field (Primary Key) in cboEmployees,
                    'and set the Record Source equal to it (All Fields)
                    frm.RecordSourc e = "Select * From tblEmployees Where [EmployeeID]= " & Forms!frmSearch ![cboEmployees].Column(0)

                    'Cascade New Instances for a better view, because if
                    'not, they would be stacked on top of one another
                    'DoCmd.RunComma nd acCmdWindowCasc ade

                    'Append it to our collection.
                    colInstance.Add Item:=frm, Key:=CStr(frm.H wnd)
                    Set frm = Nothing
                    End Function[/CODE]
                    [CODE=vb]Private Sub cmdCloseAll_Cli ck()
                    Dim Msg As String

                    'Command Button on Main Form, closes 'ALL' Instances if they exist
                    Msg = "There are no Instances of the Search Results Form to Close!"

                    If colInstance.Cou nt = 0 Then
                    MsgBox Msg, vbExclamation, "No Instances Created"
                    Else
                    Call fCloseAllInstan ces
                    End If
                    End Sub[/CODE]
                    [CODE=vb]Function fCloseAllInstan ces()
                    'Note: Leaves the copy opened directly from database window.
                    'Closes 'ALL' created Instances from Command Button on frmSearch
                    Dim lngInstanceCoun t As Long, lngCounter As Long

                    lngInstanceCoun t = colInstance.Cou nt

                    For lngCounter = 1 To lngInstanceCoun t
                    colInstance.Rem ove 1
                    Next
                    End Function[/CODE]
                    [CODE=vb]Private Sub Form_Close()
                    'Purpose: Remove this specific Instance from the colInstance collection.
                    Dim obj As Object, blnRemove As Boolean

                    'Check if this instance is in the collection.
                    '(It won't be if form was opened directly, or code was reset.)
                    For Each obj In colInstance
                    If obj.Hwnd = Me.Hwnd Then
                    blnRemove = True
                    Exit For
                    End If
                    Next

                    'Deassign the object before removing from collection.
                    Set obj = Nothing
                    If blnRemove Then
                    colInstance.Rem ove CStr(Me.Hwnd)
                    End If
                    End Sub[/CODE]

                    Comment

                    • blad3runn69
                      New Member
                      • Jul 2007
                      • 59

                      #11
                      that is cool, thank you and kudos to you ADezii. I will have a long look at your database & script, I have a lot to learn! :)

                      thank you again for your help ADezii, you are a gentleman and a scholar.

                      Comment

                      • ADezii
                        Recognized Expert Expert
                        • Apr 2006
                        • 8834

                        #12
                        Originally posted by blad3runn69
                        that is cool, thank you and kudos to you ADezii. I will have a long look at your database & script, I have a lot to learn! :)

                        thank you again for your help ADezii, you are a gentleman and a scholar.
                        Glad to be of service to you, but please do not forget to give credit to Allen Browne, since it was his original Article and code which pointed both of us in the right direction.

                        Comment

                        • blad3runn69
                          New Member
                          • Jul 2007
                          • 59

                          #13
                          allen browne is a wise owl (eg. multiple instances of a form pwns ms ... :)... I emailed & thanked mr browne 4 his boolean logic a long time ago, great minds make light work, thankyou ADezii... ;)\\

                          Comment

                          • ADezii
                            Recognized Expert Expert
                            • Apr 2006
                            • 8834

                            #14
                            Originally posted by blad3runn69
                            allen browne is a wise owl (eg. multiple instances of a form pwns ms ... :)... I emailed & thanked mr browne 4 his boolean logic a long time ago, great minds make light work, thankyou ADezii... ;)\\
                            You are quite welcome.

                            Comment

                            • blad3runn69
                              New Member
                              • Jul 2007
                              • 59

                              #15
                              managed to get it working using a filter. thought i would share for prosperity and ask about bugs :)

                              below is the OpenAClient() snippet of allen browne's managing multiple instances of a form 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_frmClient
                              frm.Visible = True
                              frm.Caption = frm.Hwnd & ", opened " & Now()

                              'added this line to display the record selected from the search form.
                              idea from allen browne's search form code

                              frm.Filter = "tblpatID = " & Forms.frmsearch .frmpatID

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

                              Set frm = Nothing
                              End Function

                              any potential problems with this?

                              thank you again for all the help, it is muchly appreciated :)

                              Comment

                              Working...