Results 1 to 6 of 6
  1. #1
    twgonder is offline Expert
    Windows 10 Access 2021
    Join Date
    Jun 2022
    Location
    Colombia
    Posts
    658

    The set command for a form, how to use variable

    I came across this little bit of code in a sample from Allen Browne,


    and I can't find an explanation of the syntax.

    Code:
     Dim frm As Form    
       'Open a new instance, show it, and set a caption.
        Set frm = New Form_frmClient
        frm.Visible = True
    The name of the form is frmClient, so I'm not sure what the Form_ in front of it is meant to do exactly.
    (Would like to understand the vocabulary pertaining to this.)
    Also, the whole Form_frmClient isn't in quotes. I'm curious why and how to use a variable instead.

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    This must be from Allen Browne's Managing Multiple Instances of Form article.

    The Form_ prefix is assigned by Access when referencing form objects in VBA Editor. See how they are listed in the VBA Editor Project Explorer window. Reports have Report_ prefix.

    It isn't in quotes because this is an object, not a string.

    Making this procedure dynamic so it can open instance of any form might require custom class code. I haven't figured out to pass an object or string to module that can be used to establish another instance. Even other code examples show explicit reference of form
    https://learn.microsoft.com/en-us/of...nces-of-a-form
    https://flylib.com/books/en/1.129.1.76/1/
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    Per the comment, it creates a second copy (instance) of the form - I'm not sure what happens with tabbed forms but if using overlapping forms, it will be visible in the access window - it will probably be sitting directly over the original form, so you'll need to move it to see the original form

    With regards syntax, it is standard syntax for classes (forms are class objects) see this link

    https://learn.microsoft.com/en-us/of...nces-of-a-form

    there is more to it than that in managing the instances but pretty sure Allen will have covered that in whatever link you found. If not, google to find out more

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    CJ, I am sure OP has all the code from Allen Browne and has no problem with the form handling. The issue is structuring this module to dynamically accept variable to specify form to act on. Allen does not deal with that nor do any other examples I can find.

    They also asked for clarification on syntax.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    the issue is structuring this module to dynamically accept variable to specify form
    only way I know of is to use a case statement (or similar). But requires knowledge of what will be passed

    Code:
    public frm as form
    
    function createfrmInstance(s as string)
    
    select case s
        case "Main"
            set frm=new Form_Main
        case "Customers"
            set frm=new Form_Customers
    end select
    
    end function

    As I said, forms are class objects - you can't 'pass' a class as a variable, only the object, and to create an new instance, you need the class.​

    I believe the issue is to do with late binding v early binding - parameters are late bound, but to create a new instance requires early binding. Other languages have the same problem

  6. #6
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 11 Office 365
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,654
    parameters are late bound, but to create a new instance requires early binding
    Evidenced by the fact it comes up with intellisense. I do a lot of oop type stuff where the forms have 0 code.
    In order to get an instance you need to set the has module property to yes and intellisense kicks in.
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

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

Similar Threads

  1. Command to display value of a variable
    By msmithtlh in forum Programming
    Replies: 2
    Last Post: 06-01-2022, 06:20 AM
  2. Replies: 3
    Last Post: 08-02-2021, 09:15 AM
  3. Replies: 5
    Last Post: 04-27-2015, 02:40 PM
  4. Pass a VB variable to SQL command
    By accessprogramer in forum Programming
    Replies: 1
    Last Post: 03-05-2015, 08:04 AM
  5. Refering to variable form names inside a variable
    By redpetfran in forum Programming
    Replies: 2
    Last Post: 05-21-2010, 01:39 PM

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