#1   Report Post  
Shawn
 
Posts: n/a
Default Msg. Box

The code below checks out something for me once the user decides to close the
program. It gives a pop up box if appropriate.

Here is my code:

Private Sub Workbook_BeforeClose(Cancel As Boolean)
If Worksheets("Daily Log of Students Seen").Range("C40").Value <
Worksheets("Daily Log of Students Seen").Range("W40").Value Then
Msg = "You have forgot to appropriately record your time!"
Ans = MsgBox(Msg, vbOKOnly + vbExclamation, "Please add your time in
or time out")
End If
End Sub

I want to add an If Then statement that if they select VB OK then the
program won't close. How do I prevent the program from closing?


--
Thanks
Shawn
  #2   Report Post  
Mexage
 
Posts: n/a
Default

Dear Shawn:

There are some things you need to address:

Try something like the following:

Private Sub Workbook_BeforeClose(Cancel As Boolean)
If Worksheets("Daily Log of Students Seen").Range("C40").Value <
Worksheets("Daily Log of Students Seen").Range("W40").Value Then

' Changes:
Msg = "You have forgot to appropriately record your time! Do you
want to close?"

if MsgBox(Msg, vbYesNo OR vbExclamation, "Please add your time in
or time out") = vbNo Then
'Cancel close
Cancel=true
End if


End If
End Sub

Hope that helps; if it does, please rate my post.

"Shawn" wrote:

The code below checks out something for me once the user decides to close the
program. It gives a pop up box if appropriate.

Here is my code:

Private Sub Workbook_BeforeClose(Cancel As Boolean)
If Worksheets("Daily Log of Students Seen").Range("C40").Value <
Worksheets("Daily Log of Students Seen").Range("W40").Value Then
Msg = "You have forgot to appropriately record your time!"
Ans = MsgBox(Msg, vbOKOnly + vbExclamation, "Please add your time in
or time out")
End If
End Sub

I want to add an If Then statement that if they select VB OK then the
program won't close. How do I prevent the program from closing?


--
Thanks
Shawn

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 10:58 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"