473,385 Members | 1,753 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,385 software developers and data experts.

Problem with Cancelling a Form

204 128KB
I have a form with which users can create a new record in the underlying table. A subform on it creates a corresponding entry in another table. On the main form there is a Cancel button which allows the user to abort the entry at any point in the process.

I need to perform some consistency checks on entries in the subform. At present this is done in a BeforeUpdate event procedure on the subform. The problem is that when the user clicks the Cancel button on the main form, the subform loses focus and its BeforeUpdate event fires before I can do any processing of the Cancel button (such as setting an "Ignore errors" flag). So the consistency checks are made and an error message produced even though the user is trying to abort the whole operation.

Is there any way I can avoid this?
(I can't put the subform consistency checks into the main form's Before/AfterUpdate events because these fire before the subform has been filled in; and I can't put them into the main form's Close event because then it's too late to allow the user to make any correction. I tried the main form's Unload event, but it couldn't find the subform's controls.)
Aug 26 '17 #1

✓ answered by NeoPa

It seems to me that this could be one of those very rare occasions when an unbound form might prove beneficial. It's certainly true that Subform records will save to table before the Cancel button can be processed.

Maybe I can lay out some alternatives to explore :
  1. Bound Form/Subform as you currently have it but attempt to determine, within the Form_BeforeUpdate() event procedure of the Subform, if the Cancel button has been clicked.
  2. Create a temporaray table, or tables, that mirror the main tables currently in use. Bind the Form & Subform to these temporary tables and copy the data across when, and only when, they've completed successfully. NB. This would work easily only for adding new records. Editing existing ones would have to be handled differently; Perhaps by changing the record sources of the two Forms based on Me.NewRecord of the main Form.
  3. Design everything as unbound and build the records from the Controls. Doesn't work well with multiple records within the same main entity.

I hope that's some help. This is a very rare situation which I've never had to think about in anger.

5 1806
NeoPa
32,556 Expert Mod 16PB
It seems to me that this could be one of those very rare occasions when an unbound form might prove beneficial. It's certainly true that Subform records will save to table before the Cancel button can be processed.

Maybe I can lay out some alternatives to explore :
  1. Bound Form/Subform as you currently have it but attempt to determine, within the Form_BeforeUpdate() event procedure of the Subform, if the Cancel button has been clicked.
  2. Create a temporaray table, or tables, that mirror the main tables currently in use. Bind the Form & Subform to these temporary tables and copy the data across when, and only when, they've completed successfully. NB. This would work easily only for adding new records. Editing existing ones would have to be handled differently; Perhaps by changing the record sources of the two Forms based on Me.NewRecord of the main Form.
  3. Design everything as unbound and build the records from the Controls. Doesn't work well with multiple records within the same main entity.

I hope that's some help. This is a very rare situation which I've never had to think about in anger.
Aug 26 '17 #2
Petrol
204 128KB
Thank you, NeoPa. It's obviously a pretty complex case. (At least that makes me feel a bit better about not being able to solve it myself!)
Suggestion 1 sounds easiest, neatest and cleanest - but I haven't found any way of doing it. When the user clicks the Cancel button on the main form, the subform loses focus and its BeforeUpdate event fires before the Cancel button Click event :(. Is there another way to find out about the Cancel?

Suggestion 2 sounds draconian - the main form is bound to the principal table of the project, with nearly 4000 records of 45 fields each. However, this form is only used for new entries - I don't need to update existing ones here. I'll have to look at this, but I quail at the thought!

Solution 3 is a bit beyond me at present. The system has been in production for months and I've only just had to add the consistency checks, so I'm hesitant to embark on a major redesign. I'd need to investigate how that could be done.

I did think about a fourth solution, to provide a separate Cancel button on the subform and tell users they must be careful to click on the button in the bit of the form which has the focus, but that's inconvenient for users and fraught with danger.

Do you think there's any future in pursuing the option I tried, of putting the consistency checks in the Unload event of the main form and returning Cancel=True if the user is cancelling? The idea would be to stop the main form Close procedure and return to editing. Would that work? I tried it, but I wasn't able to reference the relevant subform controls from the main form Unload procedure. Maybe I was not doing this correctly.
Aug 26 '17 #3
NeoPa
32,556 Expert Mod 16PB
Petrol:
Do you think there's any future in pursuing the option I tried, of putting the consistency checks in the Unload event of the main form and returning Cancel=True if the user is cancelling?
No. By then the record's already been saved. What could you do about it at that point?

You could try the Cancel button on the Subform option I suppose. You'd also need code in the Subforms Form_BeforeUpdate() event procedure to cancel the update unless previously set to be allowed. IE. The Cancel button would cancel the changes to the record and a separate Save button would be needed to set that the update be allowed. Something like a Form level flag.
Aug 27 '17 #4
Petrol
204 128KB
Um. Yes, the whole thing is much more difficult than I originally envisaged.
I'll be away from the project for a few days and then will have to carefully look at all the options - most of which you have provided. So thanks again. I'll repost when I finally get it sorted.
Peter
Aug 27 '17 #5
NeoPa
32,556 Expert Mod 16PB
Good luck anyway Peter. Nothing trivial about this one.
Aug 27 '17 #6

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

Similar topics

12
by: Tom | last post by:
Hi all, I am a newbe to javascript so I could use your help. I checked the FAQs and searched google but I could not resolve this problem. My form is as follows: <form...
1
by: Vinnie Murdico | last post by:
Hi, We have an order form on our site that is a simple HTML page that has a FORM in it. The FORM ACTION is to run a perl script that processes the order. For a long time, we've noticed on...
1
by: Dayne | last post by:
I have a problem with how visual studio.net's form designer handles form inheritance. This is what I am trying to do.. I have a base form with some controls on it..I then create a child Form from...
4
by: bnp | last post by:
Hi All, I am quite new the JavaScript. Basically I am a C++ programmer, but now I am working on JavaScript since last 5 days. I have a problem regarding the form validation. I have created a...
2
by: lgbjr | last post by:
Hi All, I see that this topic was discussed back on august 23rd, but I didn't see a real answer. I have a VB.NET MDI app. A particular menu action on the MDI parent is to call an OpenFileDialog...
4
by: szimek | last post by:
Hi, I've already posted an email with this problem, but this time I think I got a bit more info. The app I'm currently working on works like this: when user clicks on a clickable element, it...
1
by: jmartmem | last post by:
Greetings, I have a troubleshooting problem that's driving me crazy! I have a form with dozens of controls. One particular control -- a list box -- is synchronized with a combo box such that...
5
by: jmartmem | last post by:
Greetings, I have built an Update Record Form in an ASP page. This form contains a number of fields, such as text boxes and menus, to name a few. Upon clicking the 'submit' button, I want the...
6
by: Wayne | last post by:
I have a database that has been in use for a long period of time as an mde without giving any problems. I've just started making some changes to the main form which consists of a continuous form...
1
by: marciojersey | last post by:
Hi everyone. I'm having a problem with form opacity in my c# application. I have a window with a vrml viewer com control and whenever the window goes into layered mode, the vrml viewer is rendered...
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
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...
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.