Message Box Commands?

Good Afternoon!

I have another quick question about the code I am writing. This time it is for a message box.


When my user completes the form he fills out, I have programed a message box to come up and tell the user that the updates are complete.

The user clicks "OK" and then another box comes up asking the user if he wants to close the form. This is a yes/no box.

When the user clicks "yes," The form clears and then closes.

Now, when the user clicks "No" I want the message boxes to close and for nothing else to happen. However, what is actually happening is that the user clicks "No" and the form still closes.

Below is the code. I am wondering if I am using the DoCmd.Close command wrong.

Also, how do you tell the form to just close the message box?

Thank you for any help you can give me!

MsgBox "Your Weekly Report Has Been Updated. Thank you!", vbInformation + vbOKOnly, "Update Complete"
MsgBox "Close Form?", vbInformation + vbYesNo
If vbYes Then
    
    Dim i As Integer

           For i = 1 To LstNewAct.ListCount

               'Remove an item from the ListBox.
               LstNewAct.RemoveItem 0

           Next i
DoCmd.Close
    
End If

If vbNo Then

    
End If

Open in new window

MeginAsked:
Who is Participating?
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
MsgBox "Your Weekly Report Has Been Updated. Thank you!", vbInformation + vbOKOnly, "Update Complete"
If MsgBox ("Do you want to close this form?", 36,"Close Form?") = vbYes Then

           Dim i As Integer
           For i = 1 To LstNewAct.ListCount
               'Remove an item from the ListBox.
               LstNewAct.RemoveItem 0

           Next i
          DoCmd.Close , acForm, Me.Name
End If
0
 
Anthony BerenguelCommented:
Megin,

try this...
MsgBox "Your Weekly Report Has Been Updated. Thank you!", vbInformation + vbOKOnly, "Update Complete"
result = MsgBox "Close Form?", vbInformation + vbYesNo
If result =  vbYes Then
    
    Dim i As Integer

           For i = 1 To LstNewAct.ListCount

               'Remove an item from the ListBox.
               LstNewAct.RemoveItem 0

           Next i
           
           DoCmd.Close
    
End If

Open in new window

0
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
Try this:

MsgBox "Your Weekly Report Has Been Updated. Thank you!", vbInformation + vbOKOnly, "Update Complete"
If MsgBox ("Close Form?", vbInformation)  + vbYesNo) =vbYes Then
           Dim i As Integer
           For i = 1 To LstNewAct.ListCount
               'Remove an item from the ListBox.
               LstNewAct.RemoveItem 0

           Next i
          DoCmd.Close, acForm, Me.Name
End If

mx
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
MeginAuthor Commented:
I used that code, but immediatly the line that says "result v= MsgBox "Close Form?", vbInformation + vbYesNo" turned red as an error. It is saying that it is a syntax error.'

How should I change that?

Also, thank you for taking the time to help me!
0
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
No needs to use 'result' ... it was not Defined anyway ... try my approach.

mx
0
 
Anthony BerenguelCommented:
Hi Megin,

The line should read...
result = MsgBox "Close Form?", vbInformation + vbYesNo

Open in new window

instead of...
result v= MsgBox "Close Form?", vbInformation + vbYesNo

Open in new window

0
 
MeginAuthor Commented:
DatabaseMX: I had to make a small change because I was getting a syntax error message, but then it did work, except that the close box, instead of being a "Yes/No" box is not an "Ok" box. How to I make it into a yes/no box?

Here is what the code looks like now:

MsgBox "Your Weekly Report Has Been Updated. Thank you!", vbInformation + vbOKOnly, "Update Complete"
If MsgBox("Close Form?", vbInformation) + vbYesNo = vbYes Then
           Dim i As Integer
           For i = 1 To LstNewAct.ListCount
               'Remove an item from the ListBox.
               LstNewAct.RemoveItem 0

           Next i
          DoCmd.Close , acForm, Me.Name
End If

Open in new window

0
 
Anthony BerenguelCommented:
MsgBox "Your Weekly Report Has Been Updated. Thank you!", vbInformation + vbOKOnly, "Update Complete"
If MsgBox("Close Form?", vbYesNo) = vbYes Then
           Dim i As Integer
           For i = 1 To LstNewAct.ListCount
               'Remove an item from the ListBox.
               LstNewAct.RemoveItem 0

           Next i
          DoCmd.Close , acForm, Me.Name
End If

Open in new window

0
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
aebea - you copied the same code I posted and changed it ...  Please use your own code ...

mx
0
 
MeginAuthor Commented:
Aebea,  
That was almost perfect! I just ran into an type mismatch error when I click the "Yes" button. It is highlighting the DoCmd.Close  , acForm,  Me.Name

Should I just take off the acForm and Me.Name part?

Honstly, I am so ignorant of how all of this works. I am not sure why they are there. They might be super important to what I am doing. ~heavy sigh~
0
 
Anthony BerenguelCommented:
I have never used the Me.Name part of the DoCmd.Close. Personally, I tend to just use DoCmd.close. :-)
0
 
MeginAuthor Commented:
DatabaseMX

Same thing. Type mismatch. Error 13.
0
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
Sorry ... on more time:


MsgBox "Your Weekly Report Has Been Updated. Thank you!", vbInformation + vbOKOnly, "Update Complete"
If MsgBox ("Do you want to close this form?", 36,"Close Form?") = vbYes Then

           Dim i As Integer
           For i = 1 To LstNewAct.ListCount
               'Remove an item from the ListBox.
               LstNewAct.RemoveItem 0

           Next i
         DoCmd.Close acForm, Me.Name
End If
0
 
Anthony BerenguelCommented:
DatabaseMX, I really didn't mean to step on your toes there. I'm just trying to help out, and do so as quickly as possible. But since you're complaining,  I will add my two cents as well. There's nothing wrong with my initial solution so I didn't see any point of you posting your solution after mine. But I guess we're all just trying to help and get points.
0
 
MeginAuthor Commented:
Thank you so much! I really appretiate the quick help! The solution worked once I took the bits off of the end of the DoCmd.Close statement. I hope that is okay, that I took the other stuff off. <br /><br />I swear, if it weren't for you I would be beating my head on my desk for the next two days!
0
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
"so I didn't see any point of you posting your solution after mine"
Look at the time stamp ... there was no posting when I hit Submit ...

And even if there was, I posted a *different* solution ... removing code that is really not necessary. Plus, you did not Dim result ... so, and module with Option Explicit set is going to generate a compile error.

mx
0
 
Anthony BerenguelCommented:
You're right. Sorry, MX. Won't happen again. Honestly, I was just trying to help out. I wasn't trying to rip you off.
0
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
no big deal ... sorry.
0
 
Anthony BerenguelCommented:
No worries on my end. And again, I'm sorry. I realize you're a veteran expert and I don't want cause any tension between any experts here, especially the veterans.
0
 
MeginAuthor Commented:
I think you are both AWESOME!!!!!!

Again, THANK YOU!
0
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
aebea:
I was just being a dick.  Sorry.  Feel free to post whatever you want at anytime.  Believe, points are not an issue.

mx
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.