Need help coding action when Yes button is chosen

G

Guest

On a form I have a command Button that, when clicked first gives a warning
message stating what action is about to be performed. Here is the code for
the Warning message...

Private Sub cmdARCHIVE_Click()
RetValue = MsgBox("You are about to ARCHIVE the Free To Grow Silviculture
records? They will be deleted from the Silviculture table and inserted into
the ARCHIVED FreeToGrow Silviculture table. Are you sure you want to do
this?", vbYesNoCancel + vbExclamation, "WARNING")

I want to add an If Then Else statement that says if the Yes button is
chosen then execute a macro I have designed to ARCHIVE the records from one
table to another and then delete the records from the original table. Else
if the No button or the Cancel button are chosen, nothing happens. Can you
help me with this part of the code?

End Sub
 
F

fredg

On a form I have a command Button that, when clicked first gives a warning
message stating what action is about to be performed. Here is the code for
the Warning message...

Private Sub cmdARCHIVE_Click()
RetValue = MsgBox("You are about to ARCHIVE the Free To Grow Silviculture
records? They will be deleted from the Silviculture table and inserted into
the ARCHIVED FreeToGrow Silviculture table. Are you sure you want to do
this?", vbYesNoCancel + vbExclamation, "WARNING")

I want to add an If Then Else statement that says if the Yes button is
chosen then execute a macro I have designed to ARCHIVE the records from one
table to another and then delete the records from the original table. Else
if the No button or the Cancel button are chosen, nothing happens. Can you
help me with this part of the code?

End Sub

Private Sub cmdARCHIVE_Click()

Dim RetValue as Integer

RetValue = MsgBox("You are about to ARCHIVE the Free To Grow
Silviculture records? They will be deleted from the Silviculture
table and inserted into the ARCHIVED FreeToGrow Silviculture table.
Are you sure you want to do this?", vbYesNoCancel + vbExclamation,
"WARNING")

If RetValue = vbYes Then
' Run your Macro
End If

End Sub

Nothing need be added if you want nothing done if the other buttons
are clicked.
 
G

Guest

Actually, this is the correct code...

If RetValue = vbYes Then
DoCmd.RunMacro "Name of Your Macro"
End If
 

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

Top