Referencing Form Controls from a Module 
Author Message
 Referencing Form Controls from a Module

Hi,

Is it possible to write routine that accesses form
controls from a module function?

E.g. This code sits in the Module

Public Function ControlActions(Level, Action)
...
 With Forms![formName]
  Select Case Action
    Case "Lock"
       For Each Ctrl In .Controls
        Ctrl.Tag = Level & "Lockable"
        Ctrl.Locked = True
       Next Ctrl
    Case "Unlock"
         ...



Fri, 16 Dec 2005 16:21:59 GMT  
 Referencing Form Controls from a Module
Sure. That should work if the form is open.

Just pass in a reference to the form as well, i.e.:
    Public Function ControlActions(frm As Form, Action as String)
and call it like this:
    Call ControlActions(Me, "Lock")
You can then use "frm" anywhere you would "Me.".

--
Allen Browne - Microsoft MVP.  Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to the newsgroup. (Email address has spurious "_SpamTrap")


Quote:
> Is it possible to write routine that accesses form
> controls from a module function?

> E.g. This code sits in the Module

> Public Function ControlActions(Level, Action)
> ...
>  With Forms![formName]
>   Select Case Action
>     Case "Lock"
>        For Each Ctrl In .Controls
>         Ctrl.Tag = Level & "Lockable"
>         Ctrl.Locked = True
>        Next Ctrl
>     Case "Unlock"
>          ...



Fri, 16 Dec 2005 19:19:12 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Referencing a control on a form from function in module

2. referencing a form's control from a module

3. Referencing the Form from Which a Module Function Is Called

4. Referencing objects on forms from Standard Modules?

5. Referencing Form Objects - Treeview in Modules

6. Referencing forms in module level code

7. Circular Reference Between Modules when 2 Class Modules Listen to Each others Events

8. Circular Reference Between Modules when 2 Class Modules Listen to Each others Events

9. Referencing an instance of a control, from a standard module

10. passing forms and controls so I can set focus back to a form from a module

11. Make a reference to a MDI form with a reference of a MDI child form

12. passing forms and controls so I can set focus back to a form from a module

 

 
Powered by phpBB® Forum Software