Hello,
I have got a problem with a command button on my form. The problem is when you click the delete button I want it to bring up a login form as only administrators can delete records, so this works fine but once you have entered you user name & password into the box & click ok it doesnt delete the record & it isnt giving me any error messages.
Can anyone help I have put the code below:
Private sub cmdOK_click()
Dim rst As DAO.Recordset
Dim strSQL As String
Dim gt As String
If Nz(txtUserName) = "" Then
MsgBox "You must enter a user name", vbInformation, "No Name Entered"
txtUserName.SetFocus
Exit Sub
End If
If Nz(txtUserPassword) = "" Then
MsgBox "You must enter a password", vbInformation, "No Password Entered"
txtUserName.SetFocus
Exit Sub
End If
strSQL = "SELECT [userPassword],[userPriviliges] FROM [userDetails] WHERE [userName]='" & txtUserName & "';"
Set rst = CurrentDb.CreateQueryDef("", strSQL).OpenRecordset
If Not rst.EOF Then
If rst("UserPassword") = txtUserPassword Then
If rst("UserPassword") = txtUserPassword Then
Select Case rst("userPriviliges")
Case "Normal"
MsgBox "Invalid user name or password entered, only administrators can delete staff records", vbExclamation, "Invalid UserName"
txtUserName.SetFocus
Case "Super User"
DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70
End Select
Else
MsgBox "Password incorrect. Please try again", vbExclamation, "Password Incorrect"
txtUserPassword.SetFocus
End If
Else
MsgBox "Invalid user name given. please try again", vbExclamation, "Invalid User Name"
txtUserName.SetFocus
End If
rst.Close
Set rst = Nothing
intAttempts = intAttempts + 1
If intAttempts > 3 Then
MsgBox "You do not have access to this database. Please contact your system administrator.", vbCritical, "Restricted Access!"
Application.Quit
End If
DoCmd.Close acForm, "formLoginDeleteStaffDetails", acSaveNo
If intAttempts & gt = 3 Then DoCmd.Quit acQuitSaveNone
End If
End Sub
Thanks!
I have got a problem with a command button on my form. The problem is when you click the delete button I want it to bring up a login form as only administrators can delete records, so this works fine but once you have entered you user name & password into the box & click ok it doesnt delete the record & it isnt giving me any error messages.
Can anyone help I have put the code below:
Private sub cmdOK_click()
Dim rst As DAO.Recordset
Dim strSQL As String
Dim gt As String
If Nz(txtUserName) = "" Then
MsgBox "You must enter a user name", vbInformation, "No Name Entered"
txtUserName.SetFocus
Exit Sub
End If
If Nz(txtUserPassword) = "" Then
MsgBox "You must enter a password", vbInformation, "No Password Entered"
txtUserName.SetFocus
Exit Sub
End If
strSQL = "SELECT [userPassword],[userPriviliges] FROM [userDetails] WHERE [userName]='" & txtUserName & "';"
Set rst = CurrentDb.CreateQueryDef("", strSQL).OpenRecordset
If Not rst.EOF Then
If rst("UserPassword") = txtUserPassword Then
If rst("UserPassword") = txtUserPassword Then
Select Case rst("userPriviliges")
Case "Normal"
MsgBox "Invalid user name or password entered, only administrators can delete staff records", vbExclamation, "Invalid UserName"
txtUserName.SetFocus
Case "Super User"
DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70
End Select
Else
MsgBox "Password incorrect. Please try again", vbExclamation, "Password Incorrect"
txtUserPassword.SetFocus
End If
Else
MsgBox "Invalid user name given. please try again", vbExclamation, "Invalid User Name"
txtUserName.SetFocus
End If
rst.Close
Set rst = Nothing
intAttempts = intAttempts + 1
If intAttempts > 3 Then
MsgBox "You do not have access to this database. Please contact your system administrator.", vbCritical, "Restricted Access!"
Application.Quit
End If
DoCmd.Close acForm, "formLoginDeleteStaffDetails", acSaveNo
If intAttempts & gt = 3 Then DoCmd.Quit acQuitSaveNone
End If
End Sub
Thanks!