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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

form for prompting to enter data 1

Status
Not open for further replies.

AT76

Technical User
Apr 14, 2005
460
0
0
US
In my app. I pop open a form that request user input:

DoCmd.OpenForm "Frm_ResponseDate", , , , , acDialog

The problem I'm encountering is figuring out a way for the user to stop the app. if they wish to. Currently if the user closes the form the code continues to run. Is there a way to stop the code if the user closes this form?

Thanks!

 
You wanted this ?
Application.Quit

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 

You can use docmd.Quit
This will Close the Application.
In order to do this - make sure the Form Modal property is set to true - I.e. they can not set the focus to any other object. Before closing that window.
Hope this helps
 
I interpret this differently.
1) You pop up a form in dialog which halts code execution at the point of docmd.openform.
2) The user inputs some info into the pop up form
3) If they do not want to run the code they exit out but the code continues to execute.

You do not want to quit the app, but you just want to quit execution.

I would simply remove the close button from the form giving the user one way out. Put a "Cancel" or "OK" buttons on the form. I would have a public variable called "blnCanceled" and if you hit cancel set this value to true. Where the code resumes check the value of blnCanceled and if true change the value of blnCanceled to false and then exit your sub.
ex.

DoCmd.OpenForm "Frm_ResponseDate", , , , , acDialog
if blnCanceled then
blnCanceled = false
exit sub
end if
do the rest of your code.

in the form responsedate

private sub cmdCancel_Click()
blnCanceled = true ' this is a global variable
docmd.close
end sub

private sub cmdOK_Click()
docmd.close
end sub
 
Thanks MajP! Exactly what I was referring to! Works great!
 
I spoke to soon MajP... I can see that your code should work logically. For some reason mine is not. Here's what I have:

On my prompt form:
Code:
Private Sub cmdCancel_Click()
  blnCanceled = True ' this is a global variable
  DoCmd.Close acForm, "Frm_ResponseDate", acSaveYes

End Sub
I declared blnCanceled as: Public blnCanceled As Boolean



On my main form:
Code:
    If blnCanceled Then
        blnCanceled = False
    Exit Sub
    End If

For some reason after click both buttons in the main form blnCanceled = false. Also I had to use: DoCmd.Close acForm, "Frm_ResponseDate", acSaveYes because the form was not closing. Any ideas what I'm doing wrong?

Thank you!
 
Tip: use the Option Explicit instruction.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
1. Make sure the variable is public in a standard module, not at the top of the form module that you close. Public variables in a form are class variables go out of scope when you close the form. I usually make a module called "mdlGlobal" and put any global variables in there. Just be careful not to over do it with globals. I always try to keep my scope as small as possible.
2) I was a little sloppy you should always do
DoCmd.Close acForm, "Frm_ResponseDate"
vs
docmd.close
you never know what will actually close the other way. You should not have to save the form (normally used when you are in design mode).

Actually it may make more sense to switch the logic and call the boolean blnContinue. Instead of the canceled button, put this in the OK button.

Private Sub cmdOK_Click()
blnContinue = True ' this is a global variable
'msgbox blnContinue
DoCmd.Close acForm, "Frm_ResponseDate"
End Sub

Then the logic gets reversed
'error check
'msgbox blnContinue
if blnContinue then
blnContinue = false
rest of your code
end if

The reason is there is many ways a user can exit out of your form, but only one way to make it continue.

In the cmdOK click event put a msgbox to see if the blnCanceled is in fact being set.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top