Disabling fields / form based on CurrentUser() (1 Viewer)

Autoeng

Why me?
Local time
Today, 09:19
Joined
Aug 13, 2002
Messages
1,302
So that a user can enter information into one field in a protect db I put the following code into the form. There are three fields and I have disabled two of them allowing them to write to the third. However, this is a tabbed form with another form as the tab. How can I protect the tabbed form without listing each and every field as false as there are many fields on the second page. Should the code be attached to the second form or the first?

Code:
Private Sub Form_Open(Cancel As Integer)
Dim UserLoggedIn As String

UserLoggedIn = CurrentUser()

If UserLoggedIn = "username" Then
Field1.Enabled = False
Field2.Enabled = False


End If

End Sub
 

billyr

Registered User.
Local time
Today, 09:19
Joined
May 25, 2003
Messages
123
I have disabled Tabs based on user security level. On forms where I intend to manipulate the properties of controls, I rename them in a way that I can use a "For...next" loop or a Case statement, and a variable as the control name. Ex: "txtFld1...txtFld20"
 

Autoeng

Why me?
Local time
Today, 09:19
Joined
Aug 13, 2002
Messages
1,302
I have too many forms to go to that level of control and be able to remember how I controlled it. Does anyone else have any idea of how to do this?
 

Bodisathva

Registered User.
Local time
Today, 09:19
Joined
Oct 4, 2005
Messages
1,274
You can select multiple controls and assign "tag" values to them, then you hide/disable on load by iterating the controls and evaluating the tags. A single function can evaluate all:

Code:
Public Function hideShow(inForm as Form)
    Dim ctrlIDX as Integer     

    For ctrlIDX = 0 to inForm.Controls.Count-1
        If inForm.Controls(ctrlIDX).tag = "blah" then
                         'manipulate controls
        End If
    Next ctrlIDX
End Function

basically, but you get the idea.
 

Users who are viewing this thread

Top Bottom