in message:
Hi Green,
thanks for your help it works great!
That's good.
but actually i had included a user name to your previous code and it look
like this:
Yes, that changes things. Revised code below....
Private Sub cmdShowAdminArea_Click()
On Error GoTo ErrorPoint
If (Me.txtUser = "admin" And Me.txtPassword = "admin") Then
' Substitute with your own user and password between the quotes
Forms!Switchboard.Filter = "[ItemNumber] = 0 And [SwitchboardID] = 12"
Forms!Switchboard.Refresh
DoCmd.Close acForm, "frmPassword"
Else
If (Me.txtUser = "qiurong" And Me.txtPassword = "qiurong") Then
' Substitute with your own user and password between the quotes
Forms!Switchboard.Filter = "[ItemNumber] = 0 And [SwitchboardID] = 12"
Forms!Switchboard.Refresh
DoCmd.Close acForm, "frmPassword"
Else
MsgBox "Incorrect Password", vbExclamation, "Access Denied"
DoCmd.Close acForm, "frmPassword"
End If
End If
ExitPoint:
Exit Sub
ErrorPoint:
' Unexpected Error
MsgBox "The following error has occurred:" _
& vbNewLine & "Error Number: " & Err.Number _
& vbNewLine & "Error Description: " & Err.Description _
, vbExclamation, "Unexpected Error"
Resume ExitPoint
End Sub
now with your new code, i'm wondering how am i suppose to add in the user
name???
is there a way for it???
Replace the code I provided before with this.
(I know this is not the "prettiest" code, but it works)
'**************Code Start********************
Private Sub cmdShowAdminArea_Click()
On Error GoTo ErrorPoint
Dim strUser As String
Dim strEnteredUser As String
Dim strPassword As String
Dim strEnteredPassword As String
Dim intI As Integer
Dim blnOk As Boolean
strUser = "admin"
strPassword = "password"
' Set our Boolean Variable to True as default
blnOk = True
If Len(Nz(Me!txtUser, "")) = 0 Then
' User Name field blank
MsgBox "Please enter a User Name " _
& "before continuing.", vbExclamation, "Missing User Name"
' Set the focus to the text box as a visual reminder
Me.txtUser.SetFocus
GoTo ExitPoint
End If
If Len(Nz(Me!txtPassword, "")) = 0 Then
' Password field blank
MsgBox "Please enter a password " _
& "before continuing.", vbExclamation, "Missing Password"
' Set the focus to the text box as a visual reminder
Me.txtPassword.SetFocus
GoTo ExitPoint
End If
' User Name entered so remember it
strEnteredUser = Me.txtUser
' Password entered so remember it
strEnteredPassword = Me.txtPassword
' Check to see if the lengths are the same for User Name
If Len(strUser) <> Len(strEnteredUser) Then
' Supplied User Name is not the same length
MsgBox "The User Name/Password you supplied is incorrect." _
& vbNewLine & "Please see the Database Administrator " _
& "for access to these functions.", vbExclamation _
, "Access Denied"
' Close the form
DoCmd.Close acForm, "frmPassword"
GoTo ExitPoint
End If
' Check to see if the lengths are the same for password
If Len(strPassword) <> Len(strEnteredPassword) Then
' Supplied password is not the same length
MsgBox "The User Name/Password you supplied is incorrect." _
& vbNewLine & "Please see the Database Administrator " _
& "for access to these functions.", vbExclamation _
, "Access Denied"
' Close the form
DoCmd.Close acForm, "frmPassword"
GoTo ExitPoint
End If
' Now do a case-sensitive comparison on User Name
For intI = 1 To Len(strUser)
If Asc(Mid$(strUser, intI, 1)) <> _
Asc(Mid$(strEnteredUser, intI, 1)) Then
' The two user names are not the same case-wise
MsgBox "The User Name/Password you supplied is incorrect." _
& vbNewLine & "Please see the Database Administrator " _
& "for access to these functions.", vbExclamation _
, "Access Denied"
' Set the boolean to false now
blnOk = False
' Close the form
DoCmd.Close acForm, "frmPassword"
Exit For
End If
Next
' Now do a case-sensitive comparison on password
For intI = 1 To Len(strPassword)
If Asc(Mid$(strPassword, intI, 1)) <> _
Asc(Mid$(strEnteredPassword, intI, 1)) Then
' The two passwords are not the same case-wise
MsgBox "The User Name/Password you supplied is incorrect." _
& vbNewLine & "Please see the Database Administrator " _
& "for access to these functions.", vbExclamation _
, "Access Denied"
' Set the boolean to false now
blnOk = False
' Close the form
DoCmd.Close acForm, "frmPassword"
Exit For
End If
Next
' Now to test our boolean to see if it is still Ok to proceed
If blnOk = True Then
' All set, close this form and open the Admin menu
Forms!Switchboard.Filter = "[ItemNumber] = 0 And " _
& "[SwitchboardID] = 12"
Forms!Switchboard.Refresh
DoCmd.Close acForm, "frmPassword"
End If
ExitPoint:
Exit Sub
ErrorPoint:
' Unexpected Error
MsgBox "The following error has occurred:" _
& vbNewLine & "Error Number: " & Err.Number _
& vbNewLine & "Error Description: " & Err.Description _
, vbExclamation, "Unexpected Error"
Resume ExitPoint
End Sub
'**************Code End********************
Adjust for the correct user name/password you wish to use.
I must point out at this point that you may seriously want to consider
implementing full blown Access User Level Security (ULS). As
you can see, the code gets more complex, especially if you want
to have multiple User Name/Password combinations that will pass
the test. ULS gives you much tighter security than anything we
can "make up" as a developer. It is, however, a difficult concept
to grasp the first few times. If you wish to pursue this option, read
all of the ULS information I have accumulated here and practice
on dummy databases until you really have a complete understanding.
http://www.ltcomputerdesigns.com/JCReferences.html#Security
Hope that helps,