Hi guys
I need your help for the following problem:
I have created a form for quick retrieval of phone numbers and email addresses, everything works except for the delete button
I want to protect this with a password so that it cannot be accidentally deleted, but there is something wrong with my code.
When I press the delete button it asks for a password and when I press cancel the field is deleted anyway, hopefully someone of you can help me
code:
Private Sub CommandButton5_Click()
Dim password As Variant
password = Application.InputBox("Please Enter Password", "Password Protected Macro")
Select Case password
Case Is = False
'do nothing
Case Is = "23BnMed"
Case Else
MsgBox "The password you entered was incorrect"
End Select
If Me.ListBox1.ListIndex >= 0 Then
Dim sh As Worksheet
Set sh = ThisWorkbook.Sheets("AddressBook")
Dim myRow As Long
myRow = Application.WorksheetFunction.Match(Me.ListBox1.List(Me.ListBox1.ListIndex, 0), sh.Range("A:A"), 0)
sh.Range("A" & myRow).EntireRow.Delete
Call Refresh_List_Box
MsgBox "Record has been deleted", vbInformation
End If
End Sub
I need your help for the following problem:
I have created a form for quick retrieval of phone numbers and email addresses, everything works except for the delete button
I want to protect this with a password so that it cannot be accidentally deleted, but there is something wrong with my code.
When I press the delete button it asks for a password and when I press cancel the field is deleted anyway, hopefully someone of you can help me
code:
Private Sub CommandButton5_Click()
Dim password As Variant
password = Application.InputBox("Please Enter Password", "Password Protected Macro")
Select Case password
Case Is = False
'do nothing
Case Is = "23BnMed"
Case Else
MsgBox "The password you entered was incorrect"
End Select
If Me.ListBox1.ListIndex >= 0 Then
Dim sh As Worksheet
Set sh = ThisWorkbook.Sheets("AddressBook")
Dim myRow As Long
myRow = Application.WorksheetFunction.Match(Me.ListBox1.List(Me.ListBox1.ListIndex, 0), sh.Range("A:A"), 0)
sh.Range("A" & myRow).EntireRow.Delete
Call Refresh_List_Box
MsgBox "Record has been deleted", vbInformation
End If
End Sub