Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to refer to a calling form, in a module's function 1

Status
Not open for further replies.

VictoriaWass

Programmer
Jul 14, 2001
12
0
0
GB
I have a function which I want to run each time any form is opened. This function checks the id of the user, and dissables any controls on that form not relevant to them.
I want the function to run for whichever form is calling it in the load event, but I can't work out how to refer to the calling form in the function. I tried passing the name of the form as a string argument to the function, but no joy. I could put the code in the load event of each form and use "me", but it would be much neater to call the function each time. The function sits in a module.
Here's what I've done so far, and don't laugh please if I'm being very stupid..


Function super_rights(l_form As string)
Dim ctl As Control

If CurrentUser <> &quot;Admin&quot; Then

For Each ctl In l_form.Controls
If ctl.ControlType = acCommandButton Then
If ctl.Tag = &quot;super&quot; Then
ctl.Enabled = False
End If
End If
Next ctl

End If

End Function

Any help would be much appreciated. Thanks

Vicky

 
Hi Vicky!

Try it this way:

Function super_rights(l_form As string)
Dim ctl As Control

If CurrentUser <> &quot;Admin&quot; Then

For Each ctl In Forms!(l_form).Controls
If ctl.ControlType = acCommandButton Then
If ctl.Tag = &quot;super&quot; Then
ctl.Enabled = False
End If
End If
Next ctl

End If

End Function

You may not need the ! after Forms, but it should work one way or the other.

hth
Jeff Bridgham
bridgham@purdue.edu
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top