Unanswered: Enable controls based on value in tablefield
I have a pretty simple permissions setup going on my database but can't quite get it to work.
Essentially, I have a table named Users with two fields: username, and userlevel.
I would like to perform a IF THEN statement where:
If userlevel = 1 then
cmdGO.Enabled = True
Elseif userlevel = 2 Then
cmdGO.Enabled = False
I don't quite understand the concept of looping through the fields of a table and how to implement that in VBA. Could someone explain it to me and provide an example? I have other applications I would like to use this for.
Sub SetUserPermission(Byval UserName as String)
Const c_Criteria As String = "username= '@U'"
Dim lngUserLevel as Long
lngUserLevel = Nz(DLookup("userlevel", "Users", Replace(c_Criteria, "@U", UserName), 0)
If lngUserLevel = 1 then
Me.cmdGO.Enabled = True
ElseIf lngUserLevel = 2 Then
Me.cmdGO.Enabled = False
Note: If there are many levels, a Select Case statement would be more readable than a serie of If... ElseIf... ElseIf... End If:
Select Case lngUserLevel
Case 1: Me.cmdGO.Enabled = True
Case 2: Me.cmdGO.Enabled = False
Case 3: '... etc.