On Click

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Can anyone help?

I have created a MACRO that will run a delete query.

I then created a form that when the user clicks on a button it will run the
delete macro.

What I would like is to alter the default/access created VBA that is
generated for the "On Click" event of the button (code is below).

When the user clicks on the button I would like it to check a text box field
on the form where the user types in a password. If the value in this box is
the same as the value in another "Hidden" text box on the same form then the
macro will run. If the password is different then a message will appear
saying "Password incorrect"

Private Sub Delete_Click()
On Error GoTo Err_Delete_Click

Dim stDocName As String

stDocName = "Delete all"
DoCmd.RunMacro stDocName

Exit_Delete_Click:
Exit Sub

Err_Delete_Click:
MsgBox Err.Description
Resume Exit_Delete_Click

End Sub



Thanks

James
 
try

Private Sub Delete_Click()
On Error GoTo Err_Delete_Click

If Me!TextboxName = Me!HiddenTextboxName Then
DoCmd.RunMacro "Delete all"
Else
MessageBox "Request denied - invalid password."
End If

Exit_Delete_Click:
Exit Sub

Err_Delete_Click:
MsgBox Err.Description
Resume Exit_Delete_Click

End Sub

hth
 
Back
Top