I use the code below to lock and hide some of the fields on my form depending on the userid and userlevel. It works fine but the problem is that when the user opens this form I want to hide
the hide the field username. When the user opens the form it is visible and after navigating through 6-7 records it becomes invisible automatically. I want it to be hidden as soon as the form opens. I don't know why it does that???
Private Sub Form_Current()
'Build SQL String from creating recordset to determine if
'the current record is from the current user
SQL = "SELECT UserName, UserLevel FROM tblBusinessOppurtunity_Main " & _
"INNER JOIN N_tblLocalUser ON tblBusinessOppurtunity_Main.UserName = N_tblLocalUser.UID " & _
"WHERE (Opportunity_ID = " & Me.Opportunity_ID & " AND UserName = '" & LocalUser & "')" '& _
"OR USERLEVEL = 'Admin'"
objRec.Open SQL, CurrentProject.Connection, _
adOpenKeyset, adLockOptimistic, adCmdText
'If there is a match, allow the user to add, delete and edit records
If objRec.RecordCount = 1 Then
Me!UserName.Visible = False
Me.AllowAdditions = False
Me.AllowDeletions = True
Me.AllowEdits = True
Me!Combo48.Locked = True
Me!Business_Lead.Locked = True
'Else don't allow the user to add, delete and edit records
Else
Me.AllowAdditions = False
Me.AllowDeletions = False
Me.AllowEdits = False
End If
objRec.Close
End Sub
Thanx
Ekta
the hide the field username. When the user opens the form it is visible and after navigating through 6-7 records it becomes invisible automatically. I want it to be hidden as soon as the form opens. I don't know why it does that???
Private Sub Form_Current()
'Build SQL String from creating recordset to determine if
'the current record is from the current user
SQL = "SELECT UserName, UserLevel FROM tblBusinessOppurtunity_Main " & _
"INNER JOIN N_tblLocalUser ON tblBusinessOppurtunity_Main.UserName = N_tblLocalUser.UID " & _
"WHERE (Opportunity_ID = " & Me.Opportunity_ID & " AND UserName = '" & LocalUser & "')" '& _
"OR USERLEVEL = 'Admin'"
objRec.Open SQL, CurrentProject.Connection, _
adOpenKeyset, adLockOptimistic, adCmdText
'If there is a match, allow the user to add, delete and edit records
If objRec.RecordCount = 1 Then
Me!UserName.Visible = False
Me.AllowAdditions = False
Me.AllowDeletions = True
Me.AllowEdits = True
Me!Combo48.Locked = True
Me!Business_Lead.Locked = True
'Else don't allow the user to add, delete and edit records
Else
Me.AllowAdditions = False
Me.AllowDeletions = False
Me.AllowEdits = False
End If
objRec.Close
End Sub
Thanx
Ekta