Page 1 of 2
Canceling a forms OK button
Posted: Sun Dec 16, 2007 11:08 pm
by mmurdock
So when a user presses an OK button on a report form whose dialog default is set to "OK" I would like it to check to make sure that all of the form data is filled in before running the report. If it is not then pop up a message and cancel running the report. I have been able to code my form to check the fields and pop up a message box, but I do not know how to cancel running the report. Any help would be appreciated.
Thanks,
Mat
Canceling a forms OK button
Posted: Tue Dec 18, 2007 1:41 am
by Vital
Set property DialogResult to None. After then use following code:
Code: Select all
if (condition)Form1.Close();
else ......
Thank you.
Re: Canceling a forms OK button
Posted: Mon Jun 22, 2015 12:17 pm
by Jennypi
Hello,
I'm having the same request. Thanks to this topic, I've managed to write this code:
Code: Select all
if (TextBoxControl1.Control.Text=="")
{MessageBox.Show("Please enter the first sample number");}
else
{
labels.Connect();
Traits.Connect();
Form1.Close();
}
if everything is OK, the form should be closed and the report should run. With this code, the form is well closed, but the report is blank. Do I miss something in my code to render the report?
Thank you.
Re: Canceling a forms OK button
Posted: Wed Jun 24, 2015 7:30 am
by Jennypi
Hello,
Any idea to answer my question?
Thanks

Re: Canceling a forms OK button
Posted: Wed Jun 24, 2015 8:45 am
by Alex K.
Hello,
Can you please send us a sample report with test data which reproduce the issue for analysis.
Thank you.
Re: Canceling a forms OK button
Posted: Wed Jun 24, 2015 9:02 am
by Jennypi
Sure.
I'm joigning the original report, which is working:
and the modified report which is not working:
and the data file:
The modified report asks that the user must enter something in the form.
Thank you.
Re: Canceling a forms OK button
Posted: Wed Jun 24, 2015 12:36 pm
by Alex K.
Hello,
In this case you close form without render report and get the blank page.Please try to set the DialogResult property for the "Ok" button as Ok,
Thank you.
Re: Canceling a forms OK button
Posted: Wed Jun 24, 2015 1:04 pm
by Jennypi
Thank you for your reply.
I tried this. But when there is an empty string in the TextBox, the message is well displayed to the user, but the report is rendered (and showing an error message "Input string was not in a correct format."), instead of showing again the form so that the user can type something.
Look at the modified report:
Thanks.
Re: Canceling a forms OK button
Posted: Wed Jun 24, 2015 1:45 pm
by Alex K.
Hello,
Please try to use the following code:
Code: Select all
if (TextBoxControl1.Control.Text=="")
{
MessageBox.Show("Please enter the first sample number");
this.IsStopped = true;
}
else
{
labels.Connect();
Form1.Close();
}
Thank you.
Re: Canceling a forms OK button
Posted: Wed Jun 24, 2015 2:04 pm
by Jennypi
Thanks but it's not working. The code "this.IsStopped = true;" doesn't stop the report rendering.
Any other idea?

Thank you.