473,508 Members | 4,779 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to write a code to act on the yes and no on a message box

76 New Member
I have tried many thing and it just would not work.
Say I have a form with a close button on it. If I click on cancel by accident and the messeage box appears asking if I'm sure I want to close the form, and I don't want to. What coding do I use if I click no the it would just close the msgbox and leave the form open. However if I click yes, it should close the form.

Can a code be written to do this procedure?
Jan 17 '11 #1
2 8373
malcolmk
79 New Member
You just need to insert the code you want for the condition Vbyes or Vbno.
Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub Command0_Click()
  3. Dim x As Integer
  4. x = MsgBox("are you sure you want to cancel", vbYesNo)
  5. If x = vbNo Then
  6. x = MsgBox("ok don't cancel", vbOKOnly)
  7. Else
  8. x = MsgBox("ok cancelling operation as requested", vbOKOnly)
  9. End If
  10.  
  11. End Sub
  12.  
  13.  
Jan 17 '11 #2
JenniferM
33 New Member
You could try using a MsgBox here:

For instance, you could try:

Expand|Select|Wrap|Line Numbers
  1. Private Sub YourButtonName_Click()
  2.  
  3. If MsgBox("Are you sure you want to close this form?", vbYesNo + vbQuestion) = vbYes Then
  4.  
  5. DoCmd.Close
  6.  
  7. Else
  8. Exit Sub
  9. End If
  10.  
  11. End Sub
The code opens up a message box with the question, "Are you sure you want to close this form?"-- you can change this if you wish. If you click yes, the form will be closed. If not, it exits the subroutine. A pretty simple (but useful) fix. Should work for you here, I believe.
Jan 17 '11 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

27
5626
by: Sune | last post by:
Hi! Pre-requisites: ------------------- 1) Consider I'm about to write a quite large program. Say 500 K lines. 2) Part of this code will consist of 50 structs with, say, no more than at most...
1
1515
by: Jignesh Desai | last post by:
There are essentially two ways that you can write code for an ASP.NET application. Inline code Style --------------------------------------------------------------- <html> <script...
88
7953
by: Peter Olcott | last post by:
Cab you write code directly in the Common Intermediate language? I need to optimize a critical real-time function.
7
5443
by: vinthan | last post by:
hi, I am new to python. I have to write test cases in python. An application is open in the desk top ( application writen in .Net) I have to write code to get focuse the application and click on...
8
2299
by: mohammaditraders | last post by:
#include <iostream.h> #include <stdlib.h> #include <conio.h> #include <string.h> class Matrix { private : int numRows, numCols ; int elements ;
0
7128
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7332
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7502
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5057
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4715
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3206
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3191
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1565
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
426
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.