Solved

Message Box Commands?

Posted on 2012-04-05
21
328 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
 
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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Access VBA Form - Filter Multiple and/or 7 36
Combobox issue 4 27
Loop within Select Case 3 25
add more styles to my code 2 19
Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
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…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…

760 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now