Results 1 to 9 of 9
  1. #1
    Join Date
    Jun 2022
    Posts
    28

    Opening Multiple Instances of *Any* Form

    Opening multiple instances of a form isn't a problem;

    Code:
    Dim frms As Collection
    
    Public Function ShowForms(Optional closeForms As Boolean = False)
        Dim f As Form, i As Integer
    
        Set frms = New Collection
        
        If closeForms Then Exit Function
    
    
        For i = 0 To 3
            
            Set f = New Form_frmStar
            f.Visible = True
            
            frms.Add f
            
            Set f = Nothing
        Next i
    
    
    End Function
    But what if I want to pass in the name of the form so I can open multiple instances of *ANY* form?

    Code:
    Public Function ShowForms(formName as String, Optional closeForms As Boolean = False)


  2. #2
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,931
    So far as I am aware this is not possible. Only way would be to use a case statement - something like



    Code:
    Select case formname
               case "frmStar"
                     Set f = New Form_frmStar
               case "frmMoon"
                     Set f = New Form_frmMoon
            end select
    Edit - just a thought, I don't have time to experiment

    1. create a class
    2. pass the name of the form to the class
    3. then use set f=new classname

  3. #3
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    there shouldnt be any reason for 1 person to open the same form many times.

  4. #4
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,556
    Quote Originally Posted by ranman256 View Post
    there shouldnt be any reason for 1 person to open the same form many times.
    I can think of a few.
    Comparing one record to another.
    Working on a new transaction, when halfway through another transaction, due to a new enquiry.

    I work on Xero via a browser and cannot work on two companies at the same time
    I have to use one in Chrome and another in Firefox. God help us if I had to work on another company.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  5. #5
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,931
    God help us if I had to work on another company.
    There is always Opera

  6. #6
    Edgar is offline Competent Performer
    Windows 8 Access 2016
    Join Date
    Dec 2022
    Posts
    309
    I've made "compare" features at some point. You press a button and it shows another form designed to make the comparison simple: It would show the current record on top and a list of relevant records below (with a search bar) and action buttons like "Use this value" or "Expand this record".

    As for working with two records at the same time, I've solved that with a panel to the left with "Recent records", you would simply go from one to the other using that panel.

    Shall the comparison be made between more than two records, I would make some form that lets the user select multiple records and visualize only the values they need, similar to what reports do.

    I don't know, I share ranman's concern.
    Please click on the ⭐ below if this post helped you.


  7. #7
    Join Date
    Jun 2022
    Posts
    28
    Quote Originally Posted by ranman256 View Post
    there shouldnt be any reason for 1 person to open the same form many times.
    "640Kb should be enough for anyone."

    Before anyone says it, I know Bill Gates never said this. It's more of a "Let them eat cake" type of remark.


  8. #8
    orange's Avatar
    orange is offline Moderator
    Windows 10 Office 365
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870

  9. #9
    Join Date
    Jun 2022
    Posts
    28
    Quote Originally Posted by orange View Post
    You may get some insight from this YT video by Juan Soto "how to duplicate forms in memory"
    Thanks for the link to the video. Building a class to spawn the form is an interesting pattern.
    It's very similar to the method I posted above, except instead of instantiating the form class directly, they've abstracted it by another layer. They instantiate the class that instantiates the form class. I suppose it's a shortcut to setup your visibility, caption, etc...

    However, at 41:19 he states "keep in mind that you would have to have a different class for every form that you want to spawn."

    That's not exactly the kind of reusability I was hoping for. Although it's more OOP than a complex conditional.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 4
    Last Post: 07-22-2016, 06:59 AM
  2. Replies: 6
    Last Post: 05-04-2015, 08:25 AM
  3. Unique ID for Multiple Form Instances
    By mblevins in forum Database Design
    Replies: 2
    Last Post: 10-31-2013, 04:01 PM
  4. Replies: 5
    Last Post: 10-11-2013, 07:29 AM
  5. Replies: 2
    Last Post: 08-17-2011, 06:55 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums