Hello,
All I am trying to do is insert to have a form with a "Delete Record" button on it. The problem is I don't want anyone to be able to delete a record, I would like someone to have to insert a password to confirm the delete.
Any help?
Hello,
All I am trying to do is insert to have a form with a "Delete Record" button on it. The problem is I don't want anyone to be able to delete a record, I would like someone to have to insert a password to confirm the delete.
Any help?
One way:
If InputBox(...) = "YourPassword" Then
another way to get the password:
http://www.baldyweb.com/WrappedForm.htm
Thank you for response, but I am still unsure of what I specifically need to type in. Note that the current On Click command is an "EmbeddedMacro" within Access. IT is not in VBA
Sorry, I don't use macros so I'm unsure of a macro method.
Here is an example that maybe you can adapt to suit your needs.
Password is password
HTH
Last edited by burrina; 05-06-2014 at 11:00 AM. Reason: Oops
Thank you burrina! But how do I insert this into my database now?!
Burrina,
I copied both tables and both forms into my database. Then I added a command button which was for a "Open form" and I have it opening your "frmpasswordadmin" it goes through the first few commands and goes through the 2nd confirmation, but then says:
"Error 2489 (The object 'frmDelete' isnt open.) in procedure chkpswd_Click of VBA Document Form_frmpasswordadmin"
Burrina,
I copied both tables and both forms into my database. Then I added a command button which was for a "Open form" and I have it opening your "frmpasswordadmin" it goes through the first few commands and goes through the 2nd confirmation, but then says:
"Error 2489 (The object 'frmDelete' isnt open.) in procedure chkpswd_Click of VBA Document Form_frmpasswordadmin"
Of course you need to Change the name of to suit your form name.
Step 1: Click Delete Button
Step 2: Password Form Opens
Step 3: If form named in code is open, it will proceed.
You could of course use OpenArgs or
If CurrentProject.AllForms("frmYourFirmNameHere").IsL oaded = True Then
'Do Something
You NEED to Edit the Code in frmpasswordadmin and adjust to your form name.
Last edited by burrina; 05-06-2014 at 12:01 PM. Reason: Edit
Hello Burrina,
Im sorry I am veryyy new to all of this... Below is the code you gave, could you please edit it to what I will need. My form name is "NewLabReportF"
Option Compare Database
Option Explicit
Private Sub Command2_Click() 'Blank Password Not Allowed
On Error GoTo Command2_Click_Error
If IsNull(Forms!frmPassword!Text0.Value) Then
MsgBox "You cannot enter a blank Password. Try again."
Me!Text0.SetFocus
End If
If Me.Text0.Value & "'" <> Me.Text0.Value Then 'No More Than 3 Attempts Allowed
Me.Text0.Value = Me.Text0.Value + 1
If Me.Text0.Value > 3 Then
MsgBox "You may not make more than three Password entry attempts.", vbCritical + vbOKOnly, "Oops!"
DoCmd.quit
End If
MsgBox "The Password for " & Me.Text0.Value & " is incorrect." & vbCrLf & _
"Please enter your correct Password or contact your Application " & _
"Administrator.", vbOKOnly, "Password for " & Me.Text0.Value & " Incorrect"
Exit Sub
Else
If (Forms!frmPassword!Text0 = "endusersoftwareprogrammer") Then
Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "frmSetCloseState"
DoCmd.OpenForm stDocName, , , stLinkCriteria
DoCmd.Close acForm, Me.Name
End If
End If
On Error GoTo 0
Exit Sub
Command2_Click_Error:
MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure Command2_Click of VBA Document Form_frmpasswordadmin"
End Sub
Private Sub chkpswd_Click()
On Error GoTo chkpswd_Click_Error
If IsNull(Forms!frmpasswordadmin!Text0) Then 'No Blank passwords allowed
MsgBox "You cannot enter a blank Password. Try again."
Me!Text0.SetFocus
Else
'No More Than 3 Attempts Allowed
If Me.LIChk > 2 Then
MsgBox "You may not make more than three Password entry attempts.", vbCritical + vbOKOnly, "Oops!"
DoCmd.quit
ElseIf IsNull(DLookup("pw", "tblUserSecurity_Sec", "pw='" & Me.Text0 & "'")) Then
Me.LIChk = Me.LIChk + 1
MsgBox "The Password you entered is incorrect." & vbCrLf & _
"Please enter your correct Password or contact your Application " & _
"Administrator.", vbOKOnly, "Parker " & Me.Text0.Value & " Incorrect"
Else
If Forms!frmpasswordadmin!Text0 = "parker" Then
DoCmd.SetWarnings False
If MsgBox("Do you wish to delete this record?", vbYesNo, "Delete Confirmation") = vbYes Then
If MsgBox("Are you SURE you want to delete this record?" & vbCrLf & _
"This will permanently delete the record.", vbYesNo, "2nd Delete Confirmation") = vbYes Then
DoCmd.SelectObject acForm, "frmDelete"
DoCmd.RunCommand acCmdDeleteRecord
DoCmd.SetWarnings True
'Do Something Here
DoCmd.Close acForm, Me.Name
Else
'do something for other users
End If
End If
End If
End If
End If
On Error GoTo 0
Exit Sub
chkpswd_Click_Error:
MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure chkpswd_Click of VBA Document Form_frmpasswordadmin"
End Sub
Of course the password needs to be change in tblUserSecurity_Sec to parker also.
'*********************************
If IsNull(Forms!frmpasswordadmin!Text0) Then 'No Blank passwords allowed
MsgBox "You cannot enter a blank Password. Try again."
Me!Text0.SetFocus
Else
'No More Than 3 Attempts Allowed
If Me.LIChk > 2 Then
MsgBox "You may not make more than three Password entry attempts.", vbCritical + vbOKOnly, "Oops!"
DoCmd.quit
ElseIf IsNull(DLookup("pw", "tblUserSecurity_Sec", "pw='" & Me.Text0 & "'")) Then
Me.LIChk = Me.LIChk + 1
MsgBox "The Password you entered is incorrect." & vbCrLf & _
"Please enter your correct Password or contact your Application " & _
"Administrator.", vbOKOnly, "Parker " & Me.Text0.Value & " Incorrect"
Else
If Forms!frmpasswordadmin!Text0 = "parker" Then
DoCmd.SetWarnings False
If MsgBox("Do you wish to delete this record?", vbYesNo, "Delete Confirmation") = vbYes Then
If MsgBox("Are you SURE you want to delete this record?" & vbCrLf & _
"This will permanently delete the record.", vbYesNo, "2nd Delete Confirmation") = vbYes Then
DoCmd.SelectObject acForm, "NewLabReportF"
DoCmd.RunCommand acCmdDeleteRecord
DoCmd.SetWarnings True
'Do Something Here
DoCmd.Close acForm, Me.Name
Else
'do something for other users
End If
End If
End If
End If
End If
If Me.Text0.Value & "'" <> Me.Text0.Value Then 'No More Than 3 Attempts Allowed
Me.Text0.Value = Me.Text0.Value + 1
If Me.Text0.Value > 3 Then
MsgBox "You may not make more than three Password entry attempts.", vbCritical + vbOKOnly, "Oops!"
DoCmd.quit
End If
MsgBox "The Password for " & Me.Text0.Value & " is incorrect." & vbCrLf & _
"Please enter your correct Password or contact your Application " & _
"Administrator.", vbOKOnly, "Password for " & Me.Text0.Value & " Incorrect"
Exit Sub
Else
If (Forms!frmPassword!Text0 = "parker") Then
Dim stDocName As String
Dim stLinkCriteria As String
DoCmd.Close acForm, "NewLabReportF"
End If
End If
Last edited by burrina; 05-06-2014 at 12:33 PM. Reason: Forgot 2nd Code
It worked!!! Thank you
Your Very Welcome. Good Luck With Your Project.
Do you have code to capture the keyboard Delete key press? Here's what I do:
Private Sub Form_BeforeDelConfirm(Cancel As Integer, Response As Integer)
'suppress default Delete Confirm dialog box.
Response = acDataErrContinue
'cancel the automatic delete operation
Cancel = True
MsgBox "Must click Remove Test button to delete test from sample.", , "Delete"
End Sub
How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.