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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

More help on DMax+1 7
Run time error 6
Deleting record with primary key 2
Please Help 1
Macro Error 1
deletion of records 1
How do I delete a record based on a user enetered string value 1
MsgBox Macro 1

Back
Top