dbTalk Databases Forums  

Trapping the X?

comp.databases.ms-access comp.databases.ms-access


Discuss Trapping the X? in the comp.databases.ms-access forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Salad
 
Posts: n/a

Default Trapping the X? - 09-14-2010 , 11:58 PM






In a form I might have a BeforeUpdate event that does some final
validation before saving a record. Ex:
If IsNull(Me.LastName) then
msgbox "Please enter a last Name"
Me.lastname.setfocus
Cancel = True
Endif

I might have a command button called Exit where I can save the record
Me.Dirty = False
and trap the error if I attempt to close the form and not exit.

If I have nav buttons, it won't permit me to go to another record or a
new record until I've satisfied the error condition.

If I hit the X button in the upper right corner of the window to exit,
it runs the BeforeUpdate event, displays the error message, and closes
the form.

If it is a new record, the data is not saved. The form just closes.
There is no way to correct the error.

Do you employ any methodology to
1) not show the msgbox?
or
2) keep the form, with its data, open if in error? New or old rec?
or
3) use another event to trap/find errors?

Reply With Quote
  #2  
Old   
Allen Browne
 
Posts: n/a

Default Re: Trapping the X? - 09-15-2010 , 06:53 AM






See:
Losing data when you close a form
at:
http://allenbrowne.com/bug-01.html

In any recent version of Access, you should get a message if you close the
form via the big X in the top right corner. If you use the Close method
(VBA) or action (macro), you will need to explicitly save first or you get
not notification.

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.


"Salad" <salad (AT) oilandvinegar (DOT) com> wrote

Quote:
In a form I might have a BeforeUpdate event that does some final
validation before saving a record. Ex:
If IsNull(Me.LastName) then
msgbox "Please enter a last Name"
Me.lastname.setfocus
Cancel = True
Endif

I might have a command button called Exit where I can save the record
Me.Dirty = False
and trap the error if I attempt to close the form and not exit.

If I have nav buttons, it won't permit me to go to another record or a new
record until I've satisfied the error condition.

If I hit the X button in the upper right corner of the window to exit, it
runs the BeforeUpdate event, displays the error message, and closes the
form.

If it is a new record, the data is not saved. The form just closes. There
is no way to correct the error.

Do you employ any methodology to
1) not show the msgbox?
or
2) keep the form, with its data, open if in error? New or old rec?
or
3) use another event to trap/find errors?

Reply With Quote
  #3  
Old   
Salad
 
Posts: n/a

Default Re: Trapping the X? - 09-15-2010 , 11:57 AM



Allen Browne wrote:
Quote:
See:
Losing data when you close a form
at:
http://allenbrowne.com/bug-01.html

In any recent version of Access, you should get a message if you close
the form via the big X in the top right corner. If you use the Close
method (VBA) or action (macro), you will need to explicitly save first
or you get not notification.

Hi Allen:

Thanks for the link.

I decided to use a kludge. I created a TYPE array and when I enter the
B4Update I fill the array with the current data. If there is an error I
set a flag blnErr to True else False. In the unLoad event I check for
blnErr and if true I cancel and fill the fields with the array data. I
also have a Cancel button to Undo that permits the form to reset and
then a close (x) can work. A bit of typing work but it works. I wish
there were a way to trap the Close (X) button.

Amazing that its been around since A2. I'm sure more than a few have
complained.

Reply With Quote
  #4  
Old   
David W. Fenton
 
Posts: n/a

Default Re: Trapping the X? - 09-15-2010 , 09:53 PM



Salad <salad (AT) oilandvinegar (DOT) com> wrote in
news:Ws-dnXQ_1vH0zw3RnZ2dnUVZ_gOdnZ2d (AT) earthlink (DOT) com:

Quote:
Do you employ any methodology to
1) not show the msgbox?
or
2) keep the form, with its data, open if in error? New or old
rec? or
3) use another event to trap/find errors?
4) eliminate the form's X and use my own CLOSE button (which can be
disguised to look like the normal X if you want to save space).

--
David W. Fenton http://www.dfenton.com/
contact via website only http://www.dfenton.com/DFA/

Reply With Quote
  #5  
Old   
Salad
 
Posts: n/a

Default Re: Trapping the X? - 09-15-2010 , 10:25 PM



David W. Fenton wrote:

Quote:
Salad <salad (AT) oilandvinegar (DOT) com> wrote in
news:Ws-dnXQ_1vH0zw3RnZ2dnUVZ_gOdnZ2d (AT) earthlink (DOT) com:


Do you employ any methodology to
1) not show the msgbox?
or
2) keep the form, with its data, open if in error? New or old
rec? or
3) use another event to trap/find errors?


4) eliminate the form's X and use my own CLOSE button (which can be
disguised to look like the normal X if you want to save space).

How do you do that? Get in the right hand corner of the title bar?


My kludge works but I'd hate to do that for a field packed form.

Reply With Quote
  #6  
Old   
David W. Fenton
 
Posts: n/a

Default Re: Trapping the X? - 09-16-2010 , 05:43 PM



Salad <salad (AT) oilandvinegar (DOT) com> wrote in
news:0JydnTgFjKyvEwzRnZ2dnUVZ_tOdnZ2d (AT) earthlink (DOT) com:

Quote:
David W. Fenton wrote:

Salad <salad (AT) oilandvinegar (DOT) com> wrote in
news:Ws-dnXQ_1vH0zw3RnZ2dnUVZ_gOdnZ2d (AT) earthlink (DOT) com:
Do you employ any methodology to
1) not show the msgbox?
or
2) keep the form, with its data, open if in error? New or old
rec? or
3) use another event to trap/find errors?

4) eliminate the form's X and use my own CLOSE button (which can
be disguised to look like the normal X if you want to save
space).

How do you do that? Get in the right hand corner of the title
bar?
No title bar. Like this:

http://dfenton.com/DFA/Splash/bellevue.jpg

If you want to fake the title bar, you can do something like this:

http://dfenton.com/DFA/examples/assignment.gif

Quote:
My kludge works but I'd hate to do that for a field packed form.
Not sure what "that" is?

--
David W. Fenton http://www.dfenton.com/
contact via website only http://www.dfenton.com/DFA/

Reply With Quote
  #7  
Old   
Salad
 
Posts: n/a

Default Re: Trapping the X? - 09-16-2010 , 06:12 PM



David W. Fenton wrote:

Quote:
Salad <salad (AT) oilandvinegar (DOT) com> wrote in
news:0JydnTgFjKyvEwzRnZ2dnUVZ_tOdnZ2d (AT) earthlink (DOT) com:


David W. Fenton wrote:


Salad <salad (AT) oilandvinegar (DOT) com> wrote in
news:Ws-dnXQ_1vH0zw3RnZ2dnUVZ_gOdnZ2d (AT) earthlink (DOT) com:

Do you employ any methodology to
1) not show the msgbox?
or
2) keep the form, with its data, open if in error? New or old
rec? or
3) use another event to trap/find errors?

4) eliminate the form's X and use my own CLOSE button (which can
be disguised to look like the normal X if you want to save
space).

How do you do that? Get in the right hand corner of the title
bar?


No title bar. Like this:

http://dfenton.com/DFA/Splash/bellevue.jpg

If you want to fake the title bar, you can do something like this:

http://dfenton.com/DFA/examples/assignment.gif

Very cool.

Quote:
My kludge works but I'd hate to do that for a field packed form.

Not sure what "that" is?

I described what I did in a prior post; created an array, stored the
data in the B4Update, and OnUnload stopped it if there were an error and
reloaded the data. Your method has much better control.

Reply With Quote
  #8  
Old   
The Frog
 
Posts: n/a

Default Re: Trapping the X? - 09-17-2010 , 02:56 AM



I do exactly the same thing as David. I remove the title bar
completely, and I also remove the controls from forms and create my
own. It was the only way I could guarantee control over the process.
Has worked fine for years.

The Frog

Reply With Quote
  #9  
Old   
Salad
 
Posts: n/a

Default Re: Trapping the X? - 09-17-2010 , 09:21 AM



The Frog wrote:

Quote:
I do exactly the same thing as David. I remove the title bar
completely, and I also remove the controls from forms and create my
own. It was the only way I could guarantee control over the process.
Has worked fine for years.

The Frog
You guys think out of the box.

Reply With Quote
  #10  
Old   
David W. Fenton
 
Posts: n/a

Default Re: Trapping the X? - 09-17-2010 , 04:33 PM



Salad <salad (AT) oilandvinegar (DOT) com> wrote in
news:H7SdnRBggNfq5A7RnZ2dnUVZ_uednZ2d (AT) earthlink (DOT) com:

Quote:
The Frog wrote:

I do exactly the same thing as David. I remove the title bar
completely, and I also remove the controls from forms and create
my own. It was the only way I could guarantee control over the
process. Has worked fine for years.

You guys think out of the box.
Well, the second of my examples was really entirely driven by
cosmetic issues -- they wanted each main form to have a different,
as each represented one of the major areas of the app. Here are the
four main forms:

http://dfenton.com/DFA/examples/Activities.gif

http://dfenton.com/DFA/examples/assignment.gif

http://dfenton.com/DFA/examples/c_2pers.gif

They didn't want to have the standard Windows title bar there
because they wanted the whole form to be coordinated with the color
scheme.

I thought it looked so nice that I didn't rebel. And that was back
in the day when I was more pliable in regard to things like this...

--
David W. Fenton http://www.dfenton.com/
contact via website only http://www.dfenton.com/DFA/

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.