Password to delete record (1 Viewer)

hardhitter06

Registered User.
Local time
Today, 11:27
Joined
Dec 21, 2006
Messages
600
HI,

I set up a password on a delete record button to ensure the end user knows they are about to delete a record. I used the password "delete".

So when I hit the delete button at this moment, a password prompts the user and if they type "delete", a message box displays saying something along the lines of "are you sure?"

The problem is, when I hit No, I receive a debug error at the highlighted line...I'm wondering why? Do I need another piece of code to handle the "No"?

Code:
Dim strPasswd
    Dim stDocName As String
    Dim stLinkCriteria As String
    
    strPasswd = InputBox("Enter Password", "Restricted Form")


    If strPasswd = "" Or strPasswd = Empty Then
        MsgBox "No Input Provided", vbInformation, "Required Data"
        Exit Sub
    End If


    If strPasswd = "delete" Then
    DoCmd.RunCommand acCmdSelectRecord
   [B] [COLOR="Yellow"]DoCmd.RunCommand acCmdDeleteRecord[/COLOR]  [/B]    Else
        MsgBox "Sorry, you do not have access to this form", _
               vbOKOnly, "Important Information"
        Exit Sub
    End If
 

bob fitz

AWF VIP
Local time
Today, 16:27
Joined
May 23, 2011
Messages
4,726
I'm not sure that this is the "proper" way to deal with your issue but the error code added seams to work.
Code:
Dim strPasswd
    Dim stDocName As String
    Dim stLinkCriteria As String
 
On Error GoTo Err_Command6_Click_Error
    strPasswd = InputBox("Enter Password", "Restricted Form")
 
    If strPasswd = "" Or strPasswd = Empty Then
        MsgBox "No Input Provided", vbInformation, "Required Data"
        Exit Sub
    End If
 
    If strPasswd = "delete" Then
    DoCmd.RunCommand acCmdSelectRecord
    DoCmd.RunCommand acCmdDeleteRecord
    Else
        MsgBox "Sorry, you do not have access to this form", vbOKOnly, _
            "Important Information"
        Exit Sub
    End If
Exit_ErrorHandler:
  Exit Sub
Err_Command6_Click_Error:
  If err.Number = 2501 Then
    MsgBox "Delete action cancelled"
    Resume Exit_ErrorHandler
  Else
    MsgBox "Error " & err.Number & " (" & err.Description & _
        ") in procedure Command6_Click of VBA Document Form_T2 at Line " & Erl
    Resume Exit_ErrorHandler
  End If
End Sub
 

boblarson

Smeghead
Local time
Today, 08:27
Joined
Jan 12, 2001
Messages
32,059
First off what is the actual error message.

Second, your code shows the ELSE on the same line as the DoCmd so that is wrong and could be causing the error (depending on what it is).
 

hardhitter06

Registered User.
Local time
Today, 11:27
Joined
Dec 21, 2006
Messages
600
@Bob Fitz - that worked...thank you!

@Boblarson...the else was like that on my thread but within my code it was on the next line.

Thank you both though.
 

bob fitz

AWF VIP
Local time
Today, 16:27
Joined
May 23, 2011
Messages
4,726
Glad it worked for you. Good luck with your project.
 

Users who are viewing this thread

Top Bottom