Results 1 to 8 of 8
  1. #1
    Rich Fulton is offline Novice
    Windows 8 Access 2013
    Join Date
    Aug 2015
    Posts
    7

    Is Form name available in called module?


    Is the calling Form name or the event handler's sub name available in called module? I need it in order to determine the form's name as in [Forms]!someformname!some control.

    Rich

  2. #2
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    In the module behind the form, you would use "Me.Name"

    In a standard module, I would pass the form name as an argument.

    Code:
    Call DoSomething(Me.Name)
    The subroutine in a standard module would be:

    Code:
    Sub DoSomething(FName as String)
    
       Msgbox FName
    
    End Sub
    (Could also be a Function)

  3. #3
    CJ_London is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,445
    not quite sure what you are asking - the form name can be used with me.name

    alternatively, if a sub or function in a form is declared as public, and the form is open at the time you would call it from another module like this:

    if you look in the vba window navigation you will see how the class names for forms are written - Form_myformname

    and in a form module how (for example) a double click event is written - mycontrol_DblClick(Cancel As Integer)

    so put it together as

    Form_myformname.controlname.sub.mycontrol_DblClick (False)

    Note that you cannot build this dynamically

  4. #4
    Rich Fulton is offline Novice
    Windows 8 Access 2013
    Join Date
    Aug 2015
    Posts
    7
    Quote Originally Posted by Ajax View Post
    not quite sure what you are asking - the form name can be used with me.name

    alternatively, if a sub or function in a form is declared as public, and the form is open at the time you would call it from another module like this:

    if you look in the vba window navigation you will see how the class names for forms are written - Form_myformname

    and in a form module how (for example) a double click event is written - mycontrol_DblClick(Cancel As Integer)

    so put it together as

    Form_myformname.controlname.sub.mycontrol_DblClick (False)

    Note that you cannot build this dynamically
    Thanks folks, I found the solution:

    Screen.ActiveForm is the form that was active when the standard module was called.

    Rich

  5. #5
    InsuranceGuy is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Aug 2015
    Location
    Colorado
    Posts
    126
    Quote Originally Posted by Rich Fulton View Post
    Screen.ActiveForm is the form that was active when the standard module was called.
    I'd be curious if this is reliable if you have background forms with timers running. If your code is always on user interaction, you're probably safe regardless. Just be cautious until verified. Sounds suspiciously like "form on top".

  6. #6
    Rich Fulton is offline Novice
    Windows 8 Access 2013
    Join Date
    Aug 2015
    Posts
    7
    Thanks. Ill keep an eye on it.

  7. #7
    CJ_London is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,445
    also be aware that if you are in a subform, screen.activeform refers to the main form

  8. #8
    Rich Fulton is offline Novice
    Windows 8 Access 2013
    Join Date
    Aug 2015
    Posts
    7
    Appreciate your thinking on the matter. It is a main form, though.

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

Similar Threads

  1. Replies: 5
    Last Post: 01-24-2014, 09:05 AM
  2. Unload called when opening a form?
    By Kirtap in forum Programming
    Replies: 6
    Last Post: 12-11-2013, 06:23 AM
  3. Replies: 4
    Last Post: 08-16-2011, 10:04 AM
  4. Replies: 4
    Last Post: 05-16-2011, 04:58 PM
  5. Replies: 1
    Last Post: 03-26-2010, 10:32 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