473,503 Members | 1,681 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Canceling an input form

Quick question for you. I'm using a small form for users to input a range of
dates for a report (similar to the date range forms used in MS templates)
that has an ok and a cancel button. How can I set up the cancel button so
that is does just that? As it is right now, the event for the cancel button
is simply docmd.close but if I click this button, ms prompts me to enter
parameter values for begindate and enddate. If i cancel out of these
prompts, i get an error - "The OpenReport action was canceled" and if I
enter something or click ok to the prompts, the report opens with no data
for obvious reasons. How can I kill the whole process with the cancel
button?
Dec 21 '06 #1
4 2799
On Thu, 21 Dec 2006 03:00:06 GMT, Jimmy wrote:
Quick question for you. I'm using a small form for users to input a range of
dates for a report (similar to the date range forms used in MS templates)
that has an ok and a cancel button. How can I set up the cancel button so
that is does just that? As it is right now, the event for the cancel button
is simply docmd.close but if I click this button, ms prompts me to enter
parameter values for begindate and enddate. If i cancel out of these
prompts, i get an error - "The OpenReport action was canceled" and if I
enter something or click ok to the prompts, the report opens with no data
for obvious reasons. How can I kill the whole process with the cancel
button?
That error, Error 2501, is a common error caused when a report
opening is canceled.

Trap the error in whatever code event is used to open the report, i.e.

Private Sub Command12_Click()
On Error GoTo Err_Handler
DoCmd.OpenReport "ReportName" ,acViewPreview

Exit_Sub:
Exit Sub
Err_Handler:
If Err = 2501 Then
Else
MsgBox "Error " & Err.Number & ' " & Err.Description
End If
Resume Exit_Sub
End Sub
--
Fred
Please respond only to this newsgroup.
I do not reply to personal e-mail
Dec 21 '06 #2

Jimmy wrote:
Quick question for you. I'm using a small form for users to input a range of
dates for a report (similar to the date range forms used in MS templates)
that has an ok and a cancel button. How can I set up the cancel button so
that is does just that? As it is right now, the event for the cancel button
is simply docmd.close but if I click this button, ms prompts me to enter
parameter values for begindate and enddate. If i cancel out of these
prompts, i get an error - "The OpenReport action was canceled" and if I
enter something or click ok to the prompts, the report opens with no data
for obvious reasons. How can I kill the whole process with the cancel
button?
Sounds like there's something here you're not telling. Did you base
your report on a parameter query? Don't. Pass filters in the Open
event of your report. Then if you cancel, nothing should happen. Your
button should have maybe one event

DoCmd.OpenReport "ReportName",.... <somewhere out here is the filter -
just a valid WHERE clause without the WHERE keyword>.

If you don't try to open the report, then you won't get any errors,
just no open report. So I guess it might help if you posted your code.

Pieter

Dec 21 '06 #3

<pi********@hotmail.comwrote in message
news:11**********************@t46g2000cwa.googlegr oups.com...
>
Sounds like there's something here you're not telling. Did you base
your report on a parameter query? Don't. Pass filters in the Open
event of your report. Then if you cancel, nothing should happen. Your
button should have maybe one event
Yes, the form/report is based on those used in many of MS templates. When
the user opens a report the onopen event opens a form frmDateRange where the
user inputs a beginning and ending date, clicks ok and then the report opens
and uses the two values from the date range form in the reports query to
limit the data displayed. What I am looking for is a way for the user to
cancel the date range form and have that form close and essentially the
report close (since I believe it is technically open already since the
calling of frmDateRange is in the reports onopen event).
>
DoCmd.OpenReport "ReportName",.... <somewhere out here is the filter -
just a valid WHERE clause without the WHERE keyword>.

If you don't try to open the report, then you won't get any errors,
just no open report. So I guess it might help if you posted your code.
Report's OnOpen event:
Private Sub Report_Open(Cancel As Integer)
DoCmd.OpenForm "frmReportDateRange", , , , , acDialog
End Sub

Form frmDateRange onClick event for OK Button:
Private Sub cmdOK_Click()
If IsNull([BeginDate]) Or IsNull([EndDate]) Then
MsgBox "You must enter both beginning and ending dates."
DoCmd.GoToControl "BeginDate"
Else
If [BeginDate] [EndDate] Then
MsgBox "Ending date must be greater than Beginning date."
DoCmd.GoToControl "BeginDate"
Else
Me.Visible = False
End If
End If
End Sub

After clicking the OK button, the date range form becomes not visible and
the report becomes visible.

>
Pieter

Dec 21 '06 #4
Jimmy wrote:
<pi********@hotmail.comwrote in message
news:11**********************@t46g2000cwa.googlegr oups.com...
>>Sounds like there's something here you're not telling. Did you base
your report on a parameter query? Don't. Pass filters in the Open
event of your report. Then if you cancel, nothing should happen. Your
button should have maybe one event


Yes, the form/report is based on those used in many of MS templates. When
the user opens a report the onopen event opens a form frmDateRange where the
user inputs a beginning and ending date, clicks ok and then the report opens
and uses the two values from the date range form in the reports query to
limit the data displayed. What I am looking for is a way for the user to
cancel the date range form and have that form close and essentially the
report close (since I believe it is technically open already since the
calling of frmDateRange is in the reports onopen event).
>>DoCmd.OpenReport "ReportName",.... <somewhere out here is the filter -
just a valid WHERE clause without the WHERE keyword>.

If you don't try to open the report, then you won't get any errors,
just no open report. So I guess it might help if you posted your code.


Report's OnOpen event:
Private Sub Report_Open(Cancel As Integer)
DoCmd.OpenForm "frmReportDateRange", , , , , acDialog
End Sub

Form frmDateRange onClick event for OK Button:
Private Sub cmdOK_Click()
If IsNull([BeginDate]) Or IsNull([EndDate]) Then
MsgBox "You must enter both beginning and ending dates."
DoCmd.GoToControl "BeginDate"
Else
If [BeginDate] [EndDate] Then
MsgBox "Ending date must be greater than Beginning date."
DoCmd.GoToControl "BeginDate"
Else
Me.Visible = False
End If
End If
End Sub

After clicking the OK button, the date range form becomes not visible and
the report becomes visible.
Also, don't forget to close "frmReportDateRange" after it closes:

Private Sub Report_Open(Cancel As Integer)
DoCmd.OpenForm "frmReportDateRange", , , , , acDialog
' execution pauses at the line above until form is closed or hidden
' close the hidden form
DoCmd.Close acForm, "frmReportDateRange"
End Sub

--
'---------------
'John Mishefske
'---------------
Dec 22 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
7224
by: J. W. McCall | last post by:
I'm working on a MUD server and I have a thread that gets keyboard input so that you can enter commands from the command line while it's in its main server loop. Everything works fine except that...
7
2967
by: greg brant | last post by:
i have a form made up of 2 file inputs and a submit button.. the imputs are to upload images, namley jpeg's for a e-greatings thing im working on. this only works with jpegs so i have a script...
1
1279
by: Gary Brown | last post by:
Hi, If window creation cannot continue how is it cancelled within an Load event handler? Setting DialogResult to Cancel does nothing and Close() is not allowed. The form is shown modelessly...
4
4048
by: welie | last post by:
I have a problem canceling a check box update when placing a check in it. Checkbox is not bound. Here is what happens. User clicks a check box. In the BeforeUpdate method of the control, if...
1
1268
by: Lance | last post by:
I want to prevent a form from closing when the user clicks the form's Close button in the form's ControlBox (i.e., the button with the "X" in the upper-right corner of the form). Instead, I just...
6
1592
by: Kevin | last post by:
I come up with these questions during the day, do some research, and then look for experienced users' input. 1. In Access, we already know it's pretty much an automatic save if you enter data. ...
0
1622
by: rcarmich | last post by:
I am having an issue canceling a beginReceive call on a timeout. For example, the following function: public int ReadBytes(Socket theSock, byte arr, int startByte, int length, int timeout) {...
2
1824
TonFrere
by: TonFrere | last post by:
Hello, I'm building a solution using Visual Studio Windows Forms and I'm coding in C#. I have a windows form with databinded textboxes, comboboxes and a datagrid. Everything works fine until a...
3
1559
by: bonus | last post by:
Im new at Javascripting and jumped in the ocean and Im a little lost, I am trying to get a form to do 2 things: 1) write a cookie (actually several cookies) 2) submit the information to a php...
0
7202
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
7084
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...
1
6991
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5578
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5013
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
4672
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
3154
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1512
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
380
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.