473,386 Members | 1,830 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Msgbox problem

All

This is most likely a stupidly easy question, but my brain is mud (My first ever Access project I have been given is huge and complicated and learning as I go)

What I want to do is to have a message box prompt a user apon closing a form. With a YesNo option. If the user clicks yes, then the form is closed, if no then the form stays open.

I have tried Macros and VBA code for this. Also spend the last few days searching TheScripts and the Net, but not much luck.

Thanks

Martin
Nov 23 '06 #1
8 2336
nico5038
3,080 Expert 2GB
Try this code behind a button:

IF msgbox ("Sure ?",vbYesNo) = vbYes then
docmd.quit
endif

This will close the database when the Yes is clicked, else nothing will happen.

Nic;o)
Nov 23 '06 #2
Howzit Nico5038

Thank you for the reply. I gave it a go and it works fine except that I only want to close/not close the form the user has open and not the whole database.

I will see if I can alter it slightly to do what I need to.

Thanks again

Martin
Nov 23 '06 #3
NeoPa
32,556 Expert Mod 16PB
I would suggest putting the code in the OnClose event, but then I saw there was no Cancel parameter :(.
You should be able to use the following code though, to quit just the current form. I have it on a command button.
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdExit_Click()
  2.     Call DoCmd.Close(ObjectType:=acForm, ObjectName:=Name)
  3. End Sub
Nov 23 '06 #4
Hi NeoPa

Thanks for your reply. Right I have tested it and it does work, it just does not do what I am after. I need a message box to prompt the user if they are sure they want to close the form or not, so they basically have a Yes/No or OK/Cancel option.

Thanks

Martin
Nov 23 '06 #5
missinglinq
3,532 Expert 2GB
Private Sub YourExitFormButton_Click()
If MsgBox("Are You Sure ?", vbYesNo) = vbYes Then
DoCmd.Close acForm, YourFormName
End If
End Sub
Nov 23 '06 #6
MissingLinq

That's the baby!!!! Thanks man, you just made my day.

Thanks a lot!!
Nov 23 '06 #7
NeoPa
32,556 Expert Mod 16PB
Sorry,

I was responding after you saw Nico's post.
I meant to put that code (the one line) in place of the .Quit in his code rather than replace it completely.

No harm done, you have all you need :)
Nov 23 '06 #8
I have now, thank you very much.
Nov 27 '06 #9

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

Similar topics

2
by: js | last post by:
Hi all, I currently encounter a problem and it is urgent to me. After calling the MsgBox.Show(), the message box is shown with non-modal mode, what is the possible reason??? This only happen...
4
by: Lakrom | last post by:
Hi to all, how to put msgbox in this asp page, this send me a message Denied permission: 'MsgBox' <% Set Conn=server.createobject("ADODB.connection") Conn.open application("StrConRuta") set rs =...
6
by: Lapchien | last post by:
In this bit of code provided so helpfully by Nath: Private Sub Command118_Click() Dim rs As DAO.Recordset Set db = CurrentDb Set rs = db.openrecordset("IMPORT")
0
by: CFW | last post by:
I use the below code to move to the selected record in a list box to that record in another form: DoCmd.OpenForm "frmWorksheet", acNormal, , , acFormEdit, acWindowNormal rst.CursorLocation =...
7
by: Anne Richmond | last post by:
I have just returned to my first vb.net project after a few weeks and find I have a problem with Msgbox. The commands I added earlier work OK but any new ones fail to show the prompt value...
4
by: | last post by:
I have about 20 MsgBox occurance in by program, which I use to inform the user of the progress of the program, or ask confirmation of an action, or simply to act separators to various parts of the...
7
by: Bob L | last post by:
I've inserted a MsgBox in some VBScript on line 12 of an .asp page and get the following error: Microsoft VBScript runtime error '800a0046' Permission denied: 'MsgBox' /default.asp, line 12 ...
9
by: Ivan Jericevich | last post by:
In my code below at the line 'response' a blip sound is heard and the program exits the sub -- No MsgBox is displayed. What am I doing wrong? If nonNumberEntered = True Then msg = "Enter...
2
by: perkykoala | last post by:
I apologize in advance for being REALLY detailed/verbose. It's the result of staring/tweaking code for too long. Using VB 2005: I need to design a multiple choice test (unfortunately, I can't...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.