472,141 Members | 1,477 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,141 software developers and data experts.

Required Property

Access97 ---

I set the Required property for a field at the table level and I have a form
that contains that field. When I click the Close button at the top left of the
screen, I get an error message when the field is blank and Access will not let
me save the record. However, I also have a Close command button with the code:
DoCmd.Close
When I click the button, the form closes with no error message although the
field is blank. I tried changing the code to:
DoCmd.Close acForm, "MyForm"
and made no difference; the form closed although the field was blank.

What is the difference between closing the form with the form's close button and
closing the form with a coded command button? Can the Required property be made
to work with a coded command button?

Thanks!

Mark
Nov 12 '05 #1
3 2838
Hi Mark.

The Required property at the engine level does work, i.e. the record is not
saved with the field blank. The problem is with the Close action.

When you use the Close action/method, Access silently *loses* your entry
without any message to notify you. To me, that is a major data-loss bug in a
piece of software that is supposed to save entries by default, but all my
attempts to get MS to fix this (over many years) have failed.

If it is any comfort, you are just one in a long queue of people who have
been stung by this. Many just lose data without ever figuring out why
"Access sometimes doesn't save properly."

Once you know about this bug, it is not too difficult to work around it:
always force an explicit save before you issue a Close. Example:
If Me.Dirty Then
Me.Dirty = False
End If
DoCmd.Close acForm, Me.Name
That code raises an error if Dirty is not set to False (i.e. the record
cannot be saved), so control passes to your error handler and the Close is
never called.

For some of the other unfixed flaws that remain unfixed through many
versions of Access, see:
http://members.iinet.net.au/~allenbr...ips.html#flaws

--
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.

"Mark" <mm*****@earthlink.net> wrote in message
news:N8******************@newsread2.news.atl.earth link.net...
Access97 ---

I set the Required property for a field at the table level and I have a form that contains that field. When I click the Close button at the top left of the screen, I get an error message when the field is blank and Access will not let me save the record. However, I also have a Close command button with the code: DoCmd.Close
When I click the button, the form closes with no error message although the field is blank. I tried changing the code to:
DoCmd.Close acForm, "MyForm"
and made no difference; the form closed although the field was blank.

What is the difference between closing the form with the form's close button and closing the form with a coded command button? Can the Required property be made to work with a coded command button?

Thanks!

Mark

Nov 12 '05 #2
Thanks, Allen! I really appreciate your help.

Mark
"Allen Browne" <Al*********@SeeSig.Invalid> wrote in message
news:40***********************@freenews.iinet.net. au...
Hi Mark.

The Required property at the engine level does work, i.e. the record is not
saved with the field blank. The problem is with the Close action.

When you use the Close action/method, Access silently *loses* your entry
without any message to notify you. To me, that is a major data-loss bug in a
piece of software that is supposed to save entries by default, but all my
attempts to get MS to fix this (over many years) have failed.

If it is any comfort, you are just one in a long queue of people who have
been stung by this. Many just lose data without ever figuring out why
"Access sometimes doesn't save properly."

Once you know about this bug, it is not too difficult to work around it:
always force an explicit save before you issue a Close. Example:
If Me.Dirty Then
Me.Dirty = False
End If
DoCmd.Close acForm, Me.Name
That code raises an error if Dirty is not set to False (i.e. the record
cannot be saved), so control passes to your error handler and the Close is
never called.

For some of the other unfixed flaws that remain unfixed through many
versions of Access, see:
http://members.iinet.net.au/~allenbr...ips.html#flaws

--
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.

"Mark" <mm*****@earthlink.net> wrote in message
news:N8******************@newsread2.news.atl.earth link.net...
Access97 ---

I set the Required property for a field at the table level and I have a

form
that contains that field. When I click the Close button at the top left of

the
screen, I get an error message when the field is blank and Access will not

let
me save the record. However, I also have a Close command button with the

code:
DoCmd.Close
When I click the button, the form closes with no error message although

the
field is blank. I tried changing the code to:
DoCmd.Close acForm, "MyForm"
and made no difference; the form closed although the field was blank.

What is the difference between closing the form with the form's close

button and
closing the form with a coded command button? Can the Required property be

made
to work with a coded command button?

Thanks!

Mark


Nov 12 '05 #3
"Mark" <mm*****@earthlink.net> wrote in message news:<N8******************@newsread2.news.atl.eart hlink.net>...
Access97 ---

What is the difference between closing the form with the form's close button and
closing the form with a coded command button? Can the Required property be made
to work with a coded command button?

The sort answer, I believe, is "no." I'd recommend a short bit of
code that manually checks the current status of the required field(s)
in the On Unload (NOT On Close) event for the form. You can execute a
CancelEvent action to stop the form from closing if the field is
empty. (There's a great bit of example code in the CancelEvent help
for Access 97.)

Depending on how you want to treat the situation, you could go the
extra mile and include a message box, set the focus to the required
field's data entry point, and temporarily re-color that field's
background color to red.

Dennis
Nov 12 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

16 posts views Thread by Georges Heinesch | last post: by
3 posts views Thread by Mark | last post: by
3 posts views Thread by Kejpa | last post: by
2 posts views Thread by Billy | last post: by
11 posts views Thread by Naeem | last post: by
1 post views Thread by Denis | last post: by
reply views Thread by leo001 | last post: by

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.