Results 1 to 14 of 14
  1. #1
    Parker is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2014
    Posts
    76

    Access 2010 - "Delete Form" command button with a Password to confirm the delete


    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?

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    One way:

    If InputBox(...) = "YourPassword" Then

    another way to get the password:

    http://www.baldyweb.com/WrappedForm.htm
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    Parker is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2014
    Posts
    76
    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

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    Sorry, I don't use macros so I'm unsure of a macro method.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    burrina's Avatar
    burrina is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Freeport,Texas
    Posts
    1,383

    Delete Form with Password

    Here is an example that maybe you can adapt to suit your needs.

    Password is password

    HTH
    Attached Files Attached Files
    Last edited by burrina; 05-06-2014 at 11:00 AM. Reason: Oops

  6. #6
    Parker is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2014
    Posts
    76
    Thank you burrina! But how do I insert this into my database now?!

  7. #7
    Parker is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2014
    Posts
    76
    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"

  8. #8
    Parker is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2014
    Posts
    76
    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"

  9. #9
    burrina's Avatar
    burrina is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Freeport,Texas
    Posts
    1,383
    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

  10. #10
    Parker is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2014
    Posts
    76
    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

  11. #11
    burrina's Avatar
    burrina is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Freeport,Texas
    Posts
    1,383
    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

  12. #12
    Parker is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2014
    Posts
    76
    It worked!!! Thank you

  13. #13
    burrina's Avatar
    burrina is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Freeport,Texas
    Posts
    1,383
    Your Very Welcome. Good Luck With Your Project.

  14. #14
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,825
    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.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 1
    Last Post: 01-16-2014, 12:33 PM
  2. Replies: 7
    Last Post: 11-30-2013, 12:33 PM
  3. Replies: 1
    Last Post: 06-21-2013, 10:41 AM
  4. Access 2010 (accdb) "not a valid password"
    By harrypotter in forum Access
    Replies: 5
    Last Post: 08-02-2011, 10:37 AM
  5. Replies: 11
    Last Post: 03-30-2011, 01:08 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums