Solved

Message Box Commands?

Posted on 2012-04-05
21
329 Views
Last Modified: 2012-04-05
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

0
Comment
Question by:Megin
  • 8
  • 7
  • 6
21 Comments
 
LVL 10

Expert Comment

by:Anthony Berenguel
ID: 37814467
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
 
LVL 75
ID: 37814470
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
 

Author Comment

by:Megin
ID: 37814478
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
Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
LVL 75
ID: 37814486
No needs to use 'result' ... it was not Defined anyway ... try my approach.

mx
0
 
LVL 10

Expert Comment

by:Anthony Berenguel
ID: 37814487
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
 

Author Comment

by:Megin
ID: 37814492
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
 
LVL 10

Expert Comment

by:Anthony Berenguel
ID: 37814499
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
 
LVL 75

Accepted Solution

by:
DatabaseMX (Joe Anderson - Access MVP) earned 95 total points
ID: 37814505
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
 
LVL 75
ID: 37814507
aebea - you copied the same code I posted and changed it ...  Please use your own code ...

mx
0
 

Author Comment

by:Megin
ID: 37814515
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
 
LVL 10

Assisted Solution

by:Anthony Berenguel
Anthony Berenguel earned 90 total points
ID: 37814520
I have never used the Me.Name part of the DoCmd.Close. Personally, I tend to just use DoCmd.close. :-)
0
 

Author Comment

by:Megin
ID: 37814521
DatabaseMX

Same thing. Type mismatch. Error 13.
0
 
LVL 75
ID: 37814523
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
 
LVL 10

Expert Comment

by:Anthony Berenguel
ID: 37814526
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
 

Author Closing Comment

by:Megin
ID: 37814530
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
 
LVL 75
ID: 37814536
"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
 
LVL 10

Expert Comment

by:Anthony Berenguel
ID: 37814542
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
 
LVL 75
ID: 37814546
no big deal ... sorry.
0
 
LVL 10

Expert Comment

by:Anthony Berenguel
ID: 37814552
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
 

Author Comment

by:Megin
ID: 37814557
I think you are both AWESOME!!!!!!

Again, THANK YOU!
0
 
LVL 75
ID: 37814603
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

Featured Post

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question