Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding a Message box to an existing ON Click Event 2

Status
Not open for further replies.

molly

Technical User
Jul 17, 2000
219
US
I have a form button. I would like to add a message box that asks if you want to proceed to run a query.

Here is what I tried unsuccessfully. I called them part1 and part2 for illustration. Can you help me?


============================================

Private Sub cmdClearWeekPlanner_Click()

'part 1
If MsgBox("Do you want to erase the Week Planner?", vbYesNo) = vbYes Then
DoCmd.Close
End If


'part2
On Error GoTo Err_cmdClearWeekPlanner_Click

Dim stDocName As String

stDocName = "2012Qry Account Week Planner to NULL"
DoCmd.OpenQuery stDocName, acNormal, acEdit

Exit_cmdClearWeekPlanner_Click:
Exit Sub

Err_cmdClearWeekPlanner_Click:
MsgBox Err.Description
Resume Exit_cmdClearWeekPlanner_Click


End Sub
 
How are ya molly . . .

You need to restructure the logic flow of your code. Try this:
Code:
[blue]On Error GoTo GotErr
   
   Dim stDocName As String

   If MsgBox("Do you want to erase the Week Planner?", vbYesNo) = vbYes Then
      stDocName = "2012Qry Account Week Planner to NULL"
      DoCmd.OpenQuery stDocName, acNormal, acEdit
   Else
      DoCmd.Close
   End If

   Exit Sub

GotErr:
   MsgBox Err.Description[/blue]

See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
Thanks. I put an END SUB at the bottom.
If i am wrong, give a yell.
Molly
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top