Here is one method:
Assumptions -
Table named tblUsers
fields in tblUsers - USERID and PWORD
Form named frmAuthenticate
textboxes on frmAuthenticate - txtUserID and txtPword
command button on form - cmdAuthenticate
Private Sub cmdAuthenticate_Click()
On Error GoTo Err_cmdAuthenticate_Click
Dim oRS As ADODB.Recordset
strSQL = "SELECT * FROM [tblUsers] " & _
"WHERE USERID = '" & Me.txtUserID.Value & "' AND" & _
"PWORD = '" & Me.txtPword.value & "'"
Set oRS = New ADODB.Recordset
oRS.Open strSQL, CurrentProject.Connection, adOpenForwardOnly,
adLockOptimistic
'Ensure there is a match...
If oRS.EOF And oRS.BOF Then 'if this is true, there is no match...
'Insert Code to tell the User they do not have permission...
'Like a message box with no choices...
'Clean up and close recordset...
oRS.Close
Set oRS = Nothing
Exit Sub
Else
'Insert Code to allow the user to delete...
'Like setting the delete property of the form to YES...
oRS.Close
Set oRS = Nothing
End If
Exit_cmdAuthenticate_Click:
Exit Sub
Err_cmdAuthenticate_Click:
MsgBox Err.Description
Resume Exit_cmdAuthenticate_Click
The BOF (Beginning of File) EOF (End of File) method checks to see if there
is any record. If BOF and EOF are both true then the recordset is empty,
therefore no match.
If I typed it correctly you should be able to copy the above code and insert
it on the Click event for the cmdAuthenticate button. You can add additonal
code to communicate with the user as you wish.
Let me know if this helps.
Randy
Dave Hawks said:
Randy
Thanks for the suggestion, but I have no experience in passing values from a
form so I would appreciate a bit more help.
I have created the tblUsers, but I am unure of the syntax for the where
statement and how that should be inserted into my original code.
Thanks
--
Dave Hawks
:
Create a table of users. (ie. tblUsers)
Each user has a "UserID" and a "Password"
All UserIDs must be unique.
Simpley create a WHERE statement that looks at UserID and Password
Example:
UserID: dhawks
Password: pwd
Then your "test" would be:
"Select * from tblUsers WHERE UserId = '" & Me.txtUser.Value & "'AND
Password = '" Me.txtPassword & "'"
(Note single and double quotes. If you do not have experience passing a
value from a form write back.)
If BOF and EOF then '(This tests if there are any records in the recordset)
'No Match - Add code to tell user they are not allowed like your "wrong
password"
Else
'There is a match -- add code to allow them to delete
End if
Let me know if this helps
Randy
:
I am using the following code to limit the ability of users to delete records.
Private Sub Player1_BeforeUpdate(Cancel As Integer)
Dim Response As String
Dim Password, Loggin
Password = "pwd"
If Not IsNull(Player1.OldValue) Then
Response = MsgBox("To avoid unauthorised deletions please enter your
password ", vbOKOnly)
If Response = vbOK Then
Loggin = InputBox("Enter Password")
If Loggin <> Password Then
MsgBox "Wrong Password"
Cancel = True
Player1.Undo
Else
End If
End If
End If
End Sub
I would like to allocate each user their own password, can anyone suugest a
method of comparing the entered password against a list of allowable
passwords.