Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I have a warning message that will prompt 2

Status
Not open for further replies.

kat25

Technical User
Feb 26, 2003
105
US
Hi!
I want to be able to create a warning type message that would prompt the user for an action by selecting a Yes
or No type choice when selecting a button on my form that
is designed to close the form and exit the database.
Something like "Are you sure you want to close the form?
Yes, No. With the end result being, if Yes chosen, the
form closes, if No is chosen the form remains open.

I already have the command button coded to close the form
once the button is clicked, however, what I'm trying to
do is give the user a second chance to make that decision
before closing the form.

I hope I have explained this good enough for some of you to help me.

Thank you in advance.
Kat25
 
If(MsgBox(“Question”, vbYesNo, “Question Title”))=vbNo Then
Then send next message
End if

cainebean
 
Thank you for the quick response. I'm new to Access, can
you tell me where I would place the IF statement.

Thanks.
 
I used a simple macro to "close" the form and "quit".
There is no SQL code. Could you help me understand
how I would close the form and exit the database using
code and also prompting for the message?
Thanks.

 
If you set up the "Close" button using the wizard, it wrote code and attached it to the button.

Open the form in design view, right click on the close button and select "Properties". Under "Event", click the "Build" symbol. This should display the code.

Copy the code and paste it in here, and we can show you how to modify it to do as you ask.

 
Ok. Thanks.

Private Sub CloseForm_Click()
On Error GoTo Err_CloseForm_Click


DoCmd.close

Exit_CloseForm_Click:
Exit Sub

Err_CloseForm_Click:
MsgBox Err.Description
Resume Exit_CloseForm_Click

End Sub

______________
Thanks.
 
Try this (I stole Foolio's code)The line "If msgbox....... =vbNo then" should all be one line. Remove the underscore following the comma.

I tried this out on one of my Databases, and it worked fine.



Private Sub CloseForm_Click()
On Error GoTo Err_CloseForm_Click
If Msgbox("Are you sure you want to close the form?",_
vbYesNo) = vbNo Then
Exit Sub
End If


DoCmd.close

Exit_CloseForm_Click:
Exit Sub

Err_CloseForm_Click:
MsgBox Err.Description
Resume Exit_CloseForm_Click

End Sub



 
Thank you for your help. I will try that.
 
Hi GDGarth
That worked great. If I wanted the user to click Yes and have that action open up another form I called frmEmailNotification, I tried adding an ElseIf statement, but am getting an error. I would appreciate it if you could
look at this code and spot what I did wrong.
Again thank you kindly for your assistance.
**************

Private Sub CloseForm_Click()
On Error GoTo Err_CloseForm_Click
If MsgBox("Are You Sure You Want to Close the Form?", vbYesNo) = vbNo Then
Exit Sub
ElseIf MsgBox("Are You Sure You Want to Close the Form?", vbYesNo) = vbYes Then
Dim stLinkCriteria As String

stDocName = "frmEmailNotification"
DoCmd.OpenForm stDocName, , , stLinkCriteria

End If


DoCmd.close

Exit_CloseForm_Click:
Exit Sub

Err_CloseForm_Click:
MsgBox Err.Description
Resume Exit_CloseForm_Click

End Sub
 
Since your're opening another form, you have to tell it which form to close, or it will open the form and immediately close it.
I changed the "IF" statements to a select case - I think that will work better. Try this, it should work:

On Error GoTo Err_CloseForm_Click
Select Case MsgBox("are you sure?", vbYesNo)
Case vbNo
Exit Sub
Case vbYes

Dim stDocName As String
stDocName = "frmEmailNotification"
DoCmd.OpenForm stDocName
DoCmd.Close acForm, "Your first form name"

End Select
Exit_CloseForm_Click:
Exit Sub

Err_CloseForm_Click:
MsgBox Err.Description
Resume Exit_CloseForm_Click


End Sub



 
Many thanks to you, GDGarth!
That is exactly what I needed on my form.

I appreciate your time and assistance.

kat25
 
You must prompt your question and then make a decision with an if... then...
Something like this:
if msgbox("Are you sure you want to exit",vbyesno) = vbyes then
docmd.close form,formname 'or whatever you want to close
else
exit sub ' or whatever you want to do
end if
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top