Lock out a user from using a field

V

vb_Dumb

I have some code which i will post later that allows users to log in
basically it is based on a table that a form looks too to verify user
and password but i don't have any type of security levels except i
have the shift key disabled, i need all users disabled from typing in
a certian field on a form except one now i don't know VB very well at
all i got the log on and modified it to what I need so please write
out any code if you can here is the code for my log on form thanks in
advance, Dan

Private Sub cboEmployee_AfterUpdate()
'After selecting user name set focus to password field
Me.txtPassword.SetFocus
End Sub

Private Sub cmdLogin_Click()

'Check to see if data is entered into the UserName combo box

If IsNull(Me.cboEmployee) Or Me.cboEmployee = "" Then
MsgBox "You must enter a User Name.", vbOKOnly, "Required
Data"
Me.cboEmployee.SetFocus
Exit Sub
End If

'Check to see if data is entered into the password box

If IsNull(Me.txtPassword) Or Me.txtPassword = "" Then
MsgBox "You must enter a Password.", vbOKOnly, "Required
Data"
Me.txtPassword.SetFocus
Exit Sub
End If

'Check value of password in tblEmployees to see if this matches value
chosen in combo box

If Me.txtPassword.Value = DLookup("strEmpPassword",
"tblEmployees", "[lngEmpID]=" & Me.cboEmployee.Value) Then

lngMyEmpID = Me.cboEmployee.Value

'Close logon form and open splash screen

DoCmd.Close acForm, "frmLogon", acSaveNo
DoCmd.OpenForm "switchboard"

Else
MsgBox "Password Invalid. Please Try Again", vbOKOnly,
"Invalid Entry!"
Me.txtPassword.SetFocus
End If

'If User Enters incorrect password 3 times database will shutdown

intLogonAttempts = intLogonAttempts + 1
If intLogonAttempts > 3 Then
MsgBox "You do not have access to this database. Please
contact your system administrator.", vbCritical, "Restricted Access!"
Application.Quit
End If

End Sub

Private Sub Command11_Click()
On Error GoTo Err_Command11_Click


DoCmd.Quit

Exit_Command11_Click:
Exit Sub

Err_Command11_Click:
MsgBox Err.Description
Resume Exit_Command11_Click

End Sub
 
T

Tom van Stiphout

I'm guessing from your code that lngMyEmpID is a global variable. If
not, it should be (Global lngMyEmpID as Long (in a standard
module)).
Add a new field to tblEmployees and call it CanChangeSpecialField (or
something more useful). Make it a YesNo field. Set it to Yes for the
special user.
In the form's Form_Open write:
dim blnCanChangeSpecialField as boolean
blnCanChangeSpecialField = DLookup("CanChangeSpecialField",
"tblEmployees", "lngEmpID=" & lngMyEmpID )
if not blnCanChangeSpecialField then Me.txtFirstName.Locked = True
(of course change txtFirstName to whatever the control name of the
special field is)

-Tom.
Microsoft Access MVP

I have some code which i will post later that allows users to log in
basically it is based on a table that a form looks too to verify user
and password but i don't have any type of security levels except i
have the shift key disabled, i need all users disabled from typing in
a certian field on a form except one now i don't know VB very well at
all i got the log on and modified it to what I need so please write
out any code if you can here is the code for my log on form thanks in
advance, Dan

Private Sub cboEmployee_AfterUpdate()
'After selecting user name set focus to password field
Me.txtPassword.SetFocus
End Sub

Private Sub cmdLogin_Click()

'Check to see if data is entered into the UserName combo box

If IsNull(Me.cboEmployee) Or Me.cboEmployee = "" Then
MsgBox "You must enter a User Name.", vbOKOnly, "Required
Data"
Me.cboEmployee.SetFocus
Exit Sub
End If

'Check to see if data is entered into the password box

If IsNull(Me.txtPassword) Or Me.txtPassword = "" Then
MsgBox "You must enter a Password.", vbOKOnly, "Required
Data"
Me.txtPassword.SetFocus
Exit Sub
End If

'Check value of password in tblEmployees to see if this matches value
chosen in combo box

If Me.txtPassword.Value = DLookup("strEmpPassword",
"tblEmployees", "[lngEmpID]=" & Me.cboEmployee.Value) Then

lngMyEmpID = Me.cboEmployee.Value

'Close logon form and open splash screen

DoCmd.Close acForm, "frmLogon", acSaveNo
DoCmd.OpenForm "switchboard"

Else
MsgBox "Password Invalid. Please Try Again", vbOKOnly,
"Invalid Entry!"
Me.txtPassword.SetFocus
End If

'If User Enters incorrect password 3 times database will shutdown

intLogonAttempts = intLogonAttempts + 1
If intLogonAttempts > 3 Then
MsgBox "You do not have access to this database. Please
contact your system administrator.", vbCritical, "Restricted Access!"
Application.Quit
End If

End Sub

Private Sub Command11_Click()
On Error GoTo Err_Command11_Click


DoCmd.Quit

Exit_Command11_Click:
Exit Sub

Err_Command11_Click:
MsgBox Err.Description
Resume Exit_Command11_Click

End Sub
 
V

vb_Dumb

I'm guessing from your code that lngMyEmpID is a global variable. If
not, it should be (Global lngMyEmpID as Long   (in a standard
module)).
Add a new field to tblEmployees and call it CanChangeSpecialField (or
something more useful). Make it a YesNo field. Set it to Yes for the
special user.
In the form's Form_Open write:
dim blnCanChangeSpecialField as boolean
blnCanChangeSpecialField = DLookup("CanChangeSpecialField",
"tblEmployees", "lngEmpID=" & lngMyEmpID )
if not blnCanChangeSpecialField then Me.txtFirstName.Locked = True
(of course change txtFirstName to whatever the control name of the
special field is)

-Tom.
Microsoft Access MVP
I have some code which i will post later that allows users to log in
basically it is based on a table that a form looks too to verify user
and password but i don't have any type of security levels except i
have the shift key disabled, i need all users disabled from typing in
a certian field on a form except one now i don't know VB very well at
all i got the log on and modified it to what I need so please write
out any code if you can here is the code for my log on form thanks in
advance, Dan
Private Sub cboEmployee_AfterUpdate()
'After selecting user name set focus to password field
Me.txtPassword.SetFocus
End Sub
Private Sub cmdLogin_Click()
'Check to see if data is entered into the UserName combo box
   If IsNull(Me.cboEmployee) Or Me.cboEmployee = "" Then
           MsgBox "You must enter a User Name.", vbOKOnly, "Required
Data"
           Me.cboEmployee.SetFocus
       Exit Sub
   End If
'Check to see if data is entered into the password box
   If IsNull(Me.txtPassword) Or Me.txtPassword = "" Then
           MsgBox "You must enter a Password.", vbOKOnly, "Required
Data"
           Me.txtPassword.SetFocus
       Exit Sub
   End If
'Check value of password in tblEmployees to see if this matches value
chosen in combo box
   If Me.txtPassword.Value = DLookup("strEmpPassword",
"tblEmployees", "[lngEmpID]=" & Me.cboEmployee.Value) Then
       lngMyEmpID = Me.cboEmployee.Value
'Close logon form and open splash screen
       DoCmd.Close acForm, "frmLogon", acSaveNo
       DoCmd.OpenForm "switchboard"
       Else
       MsgBox "Password Invalid.  Please Try Again", vbOKOnly,
"Invalid Entry!"
       Me.txtPassword.SetFocus
   End If
'If User Enters incorrect password 3 times database will shutdown
   intLogonAttempts = intLogonAttempts + 1
   If intLogonAttempts > 3 Then
       MsgBox "You do not have access to this database.  Please
contact your system administrator.", vbCritical, "Restricted Access!"
       Application.Quit
   End If
Private Sub Command11_Click()
On Error GoTo Err_Command11_Click
   DoCmd.Quit
Exit_Command11_Click:
   Exit Sub
Err_Command11_Click:
   MsgBox Err.Description
   Resume Exit_Command11_Click


Thanks Tom honestly who knows if it's global not me that's for sure
but thank you for the response works great!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top