Results 1 to 6 of 6
  1. #1
    Timaxusa is offline Novice
    Windows 10 Access 2013 32bit
    Join Date
    Apr 2018
    Posts
    10

    Reference control of the from from function

    Hi all! Have a question. i used this code for a long time within a form and works fine:
    Dim Ctl As control
    For Each Ctl In Controls
    If Ctl.Tag = "s" Then
    Ctl.visible = False
    End If
    Next Ctl
    When I'm trying to use it in Function outside of the form, I get an error. Need to reference particular form I guess


    How would I reference "Production" form for example from function?

    Thank you!

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    Is this code in some form or control event?
    Show us the whole procedure ---from sub to end.

    To reference controls on current form you would use Me.Controls.
    We need to see where this is being done.

  3. #3
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    How would I reference "Production" form for example from function?
    two possible ways, use screen.activeform, but this only relates to the main form, not subforms.

    the other is to pass the form as a parameter


    Code:
    function changeform(frm as form)
    Dim Ctl As control
        For Each Ctl In frm.Controls
            ...
            ...
    it could be called by putting

    =changeform([FORM])

    against the form open event (where it says Event Procedure)

    or called from within the form to be changed

    changeform Me

  4. #4
    Timaxusa is offline Novice
    Windows 10 Access 2013 32bit
    Join Date
    Apr 2018
    Posts
    10
    I modified code like this and it works!
    Dim Ctl As control
    For Each Ctl In Forms![ProductionMain].Form.Controls
    If Ctl.Tag = "s" Then
    Ctl.visible = False
    End If
    Next Ctl

    Thank you all for your help!

  5. #5
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,979
    For generic solution to manage controls in any form based on their tag value see this example database
    https://www.access-programmers.co.uk...d.php?t=293439
    The code includes functions to manage the following:
    -visible/hidden , locked/unlocked, enabled/disabled
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  6. #6
    Timaxusa is offline Novice
    Windows 10 Access 2013 32bit
    Join Date
    Apr 2018
    Posts
    10
    Thank you very much for your help! All worked perfectly fine with modified code.

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

Similar Threads

  1. Replies: 7
    Last Post: 03-09-2018, 11:11 PM
  2. Subform control reference
    By SunTop in forum Forms
    Replies: 3
    Last Post: 04-26-2017, 03:50 AM
  3. Replies: 15
    Last Post: 05-12-2016, 02:27 PM
  4. Replies: 1
    Last Post: 10-06-2015, 06:50 AM
  5. Replies: 8
    Last Post: 11-04-2014, 10:44 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