Results 1 to 7 of 7
  1. #1
    dcdimon's Avatar
    dcdimon is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2013
    Location
    Bradenton, FL
    Posts
    71

    Question Usage of Screen.Activeform.ActiveControl - syntax

    I've been searching on the 'net and haven't found an answer to my question so I'm turning to this forum.

    I often use Screen.Activeform.ActiveControl to create VBA modules for use on multiple forms. What I've been looking for is a guide to how to build the script when dealing with controls on subforms or on the main form and when screen.activecontrol should be used versus screen.activeform.activecontrol. I'm looking for a basic usage guide that discusses the syntax of these functions.

    Has anyone run across something like this? Or do you have something that you've created for your own use you'd be willing to share?

    Thanks in advance for your help.

    DD

  2. #2
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    Are you looking to perform an action on the main form based on what's in the subform? or are you looking to perform some action within the subform itself? I've used the .activeform within a subform as part of the subform code. Can you give an example of what you're trying to do?

  3. #3
    dcdimon's Avatar
    dcdimon is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2013
    Location
    Bradenton, FL
    Posts
    71
    I'm not trying to do anything...I've already done it. But I'd like to be able to find a reference on how to build a VBA script using screen.(whatever) so I don't have to rebuild the wheel every time. I have found that I'm doing so much scripting (VBA) that I forget how to construct the screen.activeform functions and spend time trying to fit it into my situation.

    And I'd like to know when screen.activecontrol would, or wouldn't, work for what I'm trying to do. I haven't found any reference that states why that may or may not work.

    I found a reference sheet for referring to subform controls (Forms!mainform!subform.form!....etc) and I'd like something similar for the screen.activeform functions as well.

  4. #4
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    http://msdn.microsoft.com/en-us/libr...ffice.14).aspx

    and for its members
    http://msdn.microsoft.com/en-us/libr...ffice.14).aspx

    as for its syntax, it just seems to be Screen dot and its member.

  5. #5
    dcdimon's Avatar
    dcdimon is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2013
    Location
    Bradenton, FL
    Posts
    71
    I've seen this and it's not all that helpful.

    For instance it doesn't address how refer to a subform control; which I found to be

    Screen.Activeform.activecontrol.form.Activecontrol

    However, I haven't found out why the above works, but using Screen.ActiveControl doesn't. It would seem to be that this would be usable since the control is still active when it's referring to a VBA Module. But the module doesn't know see the control with just Screen.ActiveControl.

    So that's why I'm trying to find something that talks about the different ways to use this function.

    I'm beginning to think it doesn't exist.

  6. #6
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    The following represents the form object inside the subform container
    activecontrol.form

    The reference material you were referring to earlier will help to explain how that works... the Parent to Child thing.
    http://access.mvps.org/access/forms/frm0031.htm

  7. #7
    hapm is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2014
    Posts
    197
    Only an advice and not suitable for all situations: If you build such a generic module you can give it a reference to the controls it should act on as a parameter.

    modGenericModul:
    Code:
    Public Sub DoSomeCoolGenericStuffWithControl(TheControlToActOn As Control)
        ' Lets do the fancy generic stuff you want to do with TheControlToActOn
    End Sub
    F_TheFormThatUsesTheGenericStuff
    Code:
    Private Sub SomeControl_OnAnEvent()
        DoSomeCoolGenericStuffWithControl SomeControl
    End Sub
    The nice thing on this approach is that you don't even need the control to be active at all. You can even make it work like before and having the same as directly referencing Screen.ActiveForm.ActiveControl by calling
    Code:
    DoSomeCoolGenericStuffWithControl Screen.ActiveForm.ActiveControl

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

Similar Threads

  1. ActiveControl form Events - VBA
    By Epidural in forum Forms
    Replies: 5
    Last Post: 05-22-2012, 10:44 AM
  2. .value usage...
    By Fish218 in forum Forms
    Replies: 2
    Last Post: 03-15-2012, 02:26 PM
  3. CPU Usage
    By worldwidewall in forum Access
    Replies: 9
    Last Post: 02-20-2012, 02:31 PM
  4. Replies: 11
    Last Post: 06-05-2011, 09:51 PM
  5. Help with gotocontrol, activecontrol
    By k9drh in forum Forms
    Replies: 5
    Last Post: 04-21-2011, 10:12 AM

Tags for this Thread

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