HELP!! Form control visibility, based on user level

G

GD

I have a switchboard divided into 4 sectors, one for each of the security
levels in 004_UserAuth_tbl. I'm trying to make sectors invisible, unless the
user has the proper level to view it. My code below works for level 1,
making everything visible, but level 2 does not make its dector visible (if I
change my level in the table to 2).

What am I doing wrong?

Private Sub Form_Current()
If Val(DLookup("[Level]", "004_UserAuth_tbl", "[UserID]='" &
CurrentUser() & "'")) = 1 Then
Me.boxAcct.Visible = True
Me.lblAcctTitle.Visible = True
Me.cmdAcct1.Visible = True
Me.lblAcct1.Visible = True
Me.cmdAcct2.Visible = True
Me.lblAcct2.Visible = True
Me.cmdAcct3.Visible = True
Me.lblAcct3.Visible = True
Me.boxDCFM_TitleBox.Visible = True
Me.lblDCFM_title.Visible = True
Me.lblAnalyzePaybacks.Visible = True
Me.lblAPC.Visible = True
Me.lblRFC.Visible = True
Me.lblDCMgt.Visible = True
Me.lblProcurement.Visible = True
Me.lblBranch.Visible = True
Me.lblDCFM_PBDM.Visible = True
Me.lblDCFM_NoDM.Visible = True
Me.cmdDCFM_APC.Visible = True
Me.cmdDCFM_RFC.Visible = True
Me.cmdDCFM_DCMgmt.Visible = True
Me.cmdDCFM_Proc.Visible = True
Me.cmdDCFM_Branch.Visible = True
Me.cmdDCFM_PBDM.Visible = True
Me.cmdDCFM_NoDM.Visible = True
Else
Me.boxAcct.Visible = False
Me.lblAcctTitle.Visible = False
Me.cmdAcct1.Visible = False
Me.lblAcct1.Visible = False
Me.cmdAcct2.Visible = False
Me.lblAcct2.Visible = False
Me.cmdAcct3.Visible = False
Me.lblAcct3.Visible = False
Me.boxDCFM_TitleBox.Visible = False
Me.lblDCFM_title.Visible = False
Me.lblAnalyzePaybacks.Visible = False
Me.lblAPC.Visible = False
Me.lblRFC.Visible = False
Me.lblDCMgt.Visible = False
Me.lblProcurement.Visible = False
Me.lblBranch.Visible = False
Me.lblDCFM_PBDM.Visible = False
Me.lblDCFM_NoDM.Visible = False
Me.cmdDCFM_APC.Visible = False
Me.cmdDCFM_RFC.Visible = False
Me.cmdDCFM_DCMgmt.Visible = False
Me.cmdDCFM_Proc.Visible = False
Me.cmdDCFM_Branch.Visible = False
Me.cmdDCFM_PBDM.Visible = False
Me.cmdDCFM_NoDM.Visible = False
End If

If Val(DLookup("[Level]", "004_UserAuth_tbl", "[UserID]='" &
CurrentUser() & "'")) = 2 Then
Me.boxAcct.Visible = True
Me.lblAcctTitle.Visible = True
Me.cmdAcct1.Visible = True
Me.lblAcct1.Visible = True
Me.cmdAcct2.Visible = True
Me.lblAcct2.Visible = True
Me.cmdAcct3.Visible = True
Me.lblAcct3.Visible = True
Else
Me.boxAcct.Visible = False
Me.lblAcctTitle.Visible = False
Me.cmdAcct1.Visible = False
Me.lblAcct1.Visible = False
Me.cmdAcct2.Visible = False
Me.lblAcct2.Visible = False
Me.cmdAcct3.Visible = False
Me.lblAcct3.Visible = False
End If

End Sub
 
D

Duane Hookom

I would use the tag property of the controls to set visibility. The code
could then loop through all the controls to check the tag values. You might
be able to use something like the following where you have set the tag
property of controls to something like "sec1".

Dim ctrl as Control
Dim intSecLevel as Integer
Dim strTagValue as String
intSecLevel = Val(DLookup("[Level]", "004_UserAuth_tbl", "[UserID]='" &
CurrentUser() & "'"))
For Each ctrl in Me.Controls
strTagValue = ctrl.Tag & ""
If Instr(strTagValue,"Sec") > 0 Then
ctrl.Visible = Instr(strTagValue,Cstr(intSecLevel)) > 0
End If
Next

--
Duane Hookom
Microsoft Access MVP


GD said:
I have a switchboard divided into 4 sectors, one for each of the security
levels in 004_UserAuth_tbl. I'm trying to make sectors invisible, unless the
user has the proper level to view it. My code below works for level 1,
making everything visible, but level 2 does not make its dector visible (if I
change my level in the table to 2).

What am I doing wrong?

Private Sub Form_Current()
If Val(DLookup("[Level]", "004_UserAuth_tbl", "[UserID]='" &
CurrentUser() & "'")) = 1 Then
Me.boxAcct.Visible = True
Me.lblAcctTitle.Visible = True
Me.cmdAcct1.Visible = True
Me.lblAcct1.Visible = True
Me.cmdAcct2.Visible = True
Me.lblAcct2.Visible = True
Me.cmdAcct3.Visible = True
Me.lblAcct3.Visible = True
Me.boxDCFM_TitleBox.Visible = True
Me.lblDCFM_title.Visible = True
Me.lblAnalyzePaybacks.Visible = True
Me.lblAPC.Visible = True
Me.lblRFC.Visible = True
Me.lblDCMgt.Visible = True
Me.lblProcurement.Visible = True
Me.lblBranch.Visible = True
Me.lblDCFM_PBDM.Visible = True
Me.lblDCFM_NoDM.Visible = True
Me.cmdDCFM_APC.Visible = True
Me.cmdDCFM_RFC.Visible = True
Me.cmdDCFM_DCMgmt.Visible = True
Me.cmdDCFM_Proc.Visible = True
Me.cmdDCFM_Branch.Visible = True
Me.cmdDCFM_PBDM.Visible = True
Me.cmdDCFM_NoDM.Visible = True
Else
Me.boxAcct.Visible = False
Me.lblAcctTitle.Visible = False
Me.cmdAcct1.Visible = False
Me.lblAcct1.Visible = False
Me.cmdAcct2.Visible = False
Me.lblAcct2.Visible = False
Me.cmdAcct3.Visible = False
Me.lblAcct3.Visible = False
Me.boxDCFM_TitleBox.Visible = False
Me.lblDCFM_title.Visible = False
Me.lblAnalyzePaybacks.Visible = False
Me.lblAPC.Visible = False
Me.lblRFC.Visible = False
Me.lblDCMgt.Visible = False
Me.lblProcurement.Visible = False
Me.lblBranch.Visible = False
Me.lblDCFM_PBDM.Visible = False
Me.lblDCFM_NoDM.Visible = False
Me.cmdDCFM_APC.Visible = False
Me.cmdDCFM_RFC.Visible = False
Me.cmdDCFM_DCMgmt.Visible = False
Me.cmdDCFM_Proc.Visible = False
Me.cmdDCFM_Branch.Visible = False
Me.cmdDCFM_PBDM.Visible = False
Me.cmdDCFM_NoDM.Visible = False
End If

If Val(DLookup("[Level]", "004_UserAuth_tbl", "[UserID]='" &
CurrentUser() & "'")) = 2 Then
Me.boxAcct.Visible = True
Me.lblAcctTitle.Visible = True
Me.cmdAcct1.Visible = True
Me.lblAcct1.Visible = True
Me.cmdAcct2.Visible = True
Me.lblAcct2.Visible = True
Me.cmdAcct3.Visible = True
Me.lblAcct3.Visible = True
Else
Me.boxAcct.Visible = False
Me.lblAcctTitle.Visible = False
Me.cmdAcct1.Visible = False
Me.lblAcct1.Visible = False
Me.cmdAcct2.Visible = False
Me.lblAcct2.Visible = False
Me.cmdAcct3.Visible = False
Me.lblAcct3.Visible = False
End If

End Sub
 
Top