[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

How do I get a Access VBA Yes/No message box to either apply/don't apply

Posted on 2014-02-12
8
Medium Priority
?
15,552 Views
Last Modified: 2014-02-12
I have a checkbox which I would like to have a  "Are you sure you want to make this change?" prompt with a Yes and No button. If they clicked yes, obviously the change would apply. If they click no, I would like the the dialog box to exit without any change to the check box.

The VBA code I have tied to the BeforeUpdate field of this check box is:

Private Sub Inactive_BeforeUpdate(Cancel As Integer)

Dim Response As Integer
Response = MsgBox("Do you want to change the status of this client?", vbYesNo + vbQuestion, "Client Prompt")
If Response = vbYes Then
MsgBox "The user status has been changed", vbOKOnly, "Confirmation..."
Else
MsgBox "The user status has NOT been changed"
End If

End Sub


I'm no programmer but have tried various code formats based on web research but none are fixing my problem.
0
Comment
Question by:OneByte
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 54

Accepted Solution

by:
Rgonzo1971 earned 1000 total points
ID: 39853890
Hi,

pls try

Private Sub Inactive_BeforeUpdate(Cancel As Integer)

Dim Response As Integer
Response = MsgBox("Do you want to change the status of this client?", vbYesNo + vbQuestion, "Client Prompt")
If Response = vbYes Then
MsgBox "The user status has been changed", vbOKOnly, "Confirmation..."
Else
Cancel = True
MsgBox "The user status has NOT been changed"
End If

End Sub

Open in new window

Regards
0
 
LVL 120

Assisted Solution

by:Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1) earned 1000 total points
ID: 39853903
Private Sub Inactive_BeforeUpdate(Cancel As Integer)

Dim Response As Integer
Response = MsgBox("Do you want to change the status of this client?", vbYesNo + vbQuestion, "Client Prompt")
If Response = vbYes Then
MsgBox "The user status has been changed", vbOKOnly, "Confirmation..."
Else
MsgBox "The user status has NOT been changed"

'ADD this line
Cancel = True

End If

End Sub

if you don't want the message when No is selected, just remove the line

MsgBox "The user status has NOT been changed"
0
 
LVL 3

Expert Comment

by:0Doc
ID: 39853917
You almost have it.  The thing you have to do is reset the checkbox value if they choose not to change it (because they already clicked it to change it), so you have to set it back.  Try this:

Dim Response As Integer, CheckboxValue
Response = MsgBox("Do you want to change the status of this client?", vbYesNo + vbQuestion, "Client Prompt")
If Response = vbYes Then
  MsgBox "The user status has been changed", vbOKOnly, "Confirmation..."
Else
  If Checkbox.Value = True Then
    Checkbox.Value = False
  Else
    Checkbox.Value = True
  End If
  MsgBox "The user status has NOT been changed"
End If
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Closing Comment

by:OneByte
ID: 39853976
Perfect! That did it Rgonzo1971 and Rey Obrero.

0Doc I received a debug error for line: If Checkbox.Value = True Then

Thank you all for your help and time.
0
 
LVL 3

Expert Comment

by:0Doc
ID: 39854362
Just an FYI since you have it solved.  The debug error is probably because of the name of the checkbox.  I called mine Checkbox.  If you have a different name for your checkbox, you'll need to put that name into the code in the place of "Checkbox"
0
 

Author Comment

by:OneByte
ID: 39854481
0Doc I tried just for kicks and changed Checkbox to Inactive with the code you provided but received "Inactive.Value = False"
Inactive is the name of my check box.

Sorry guys the suggested syntax did fix my functionality with the vbYesNo but  now when I try to close the form, window, or click another button on the form to open another form I get the dialog prompt that set on the check box. The code is only set to the BeforeUpdate area of the check box.
Please advise.
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 39854496
Private Sub Inactive_BeforeUpdate(Cancel As Integer)

Dim Response As Integer
Response = MsgBox("Do you want to change the status of this client?", vbYesNo + vbQuestion, "Client Prompt")
If Response = vbYes Then
MsgBox "The user status has been changed", vbOKOnly, "Confirmation..."
Else
MsgBox "The user status has NOT been changed"

'ADD this line
Cancel = True
me.Inactive.undo
exit sub


End If

End Sub
0
 

Author Comment

by:OneByte
ID: 39854591
Corrected my problem. Thanks Rey!!
0

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

Microsoft's Excel has many features that most people will never need nor take advantage of.  Conditional formatting is one feature that you may find a necessity once you start using it.
Quickbooks hosting can do wonders to your enterprise but considering the points elaborated in the article which will help you to better analyze the outcomes. So scan your business, its needs and then move to the new world of limitless benefits.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

830 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