Enable command button if no null entries in form

  • Thread starter Thread starter Haleigh
  • Start date Start date
H

Haleigh

Design advice please.

I want to verify that the user has completed ALL form
fields before enabling a command button on the form. It
seems silly to have to run the code on each fields'
AfterUpdate event. Where is the best place to put the code?
 
Try adding a command button that closes the form and run
the code from OnClick of the commad button.
 
Allen, I've learned that BeforeUpdate event works when the
focus moves to another record. That will not happen in my
case, since only one record at a time is added with the
form. Do you have another suggestion?

Haleigh
 
The form's BeforeUpdate event fires before the record is saved, regarless of
what initiates the save.

Do you want something that works if the user closes the form?
Presses Shift+Enter?
Chooses Save Record from the Records menu?
Filters the form?
Sorts the form?
Presses Ctrl+F4 or Alt+F4?
Chooses Close or Exit from the File menu?
Or any number of other possible triggers that could save the record?

Assuming this is a bound form, Form_BeforeUpdate is the *only* reliable
approach to checking the data before the record is saved.
 
Hi again, Allen. Well, this probably seems silly, but I
don't want the Save button enabled until all the fields
are filled in. The AfterUpdate event for each field could
trigger the check to make sure everything is filled in,
but that is alot of code for every field on the form. I
did a test in the form's AfterUpdate event by putting in a
message box but in truth unless I move to another record
(which is not an option for this form), I can't see how
the AfterUpdate for the form can be triggered.

Should I content myself with (a) checking valid entries
for each field on the form; or (b) go ahead and enable the
Save button, but tell the person that they haven't
completed all the fields; or (c) anything else you could
suggest.
 
If you want to disable the command button, and enable it only when all
controls have been entered, and prevent the user from saving the record any
other way, you will have to:

1. Use the AfterUpdate event procedure of *every* control to call a
procedure that loops through all the relevent controls on the form, and
tests them for Null, enabling the button only if none Is Null.

2. Handle the Click event of the button so that it forces the save, and
closes the form only if the save succeeds, to avoid the bug in Access where
the Close action/method silently loses the record if it cannot be saved:
http://members.iinet.net.au/~allenbrowne/bug-01.html

3. Set up code that cancels the Unload event of the form if the event was
triggered by any means other than your command button (by which time the
record is alreay saved), and/or disable/remove the control box and close
buttons on both the form and on the Access application, as well as the
menus, toolbars, keyboard shortcuts, and right-mouse shortcuts.

Sorry: I don't see the point of forcing the user into that kind of
straight-jacket. What was the reason for doing it that way again?

I guess the code-free solution of setting the Required property to Yes for
each field in table design is not appealing either?

I think that has given you at least one option for each of our a, b, and c
choices. :-) You have the advantage of knowing what you want to achieve and
why.
 
Back
Top