Hugh O'Neill said:
What I try to do in my applications is to make buttons available
(enabled) only when it is appropriate for them to be used. Your 'Save
Record' button, for instance should only be enabled when it is OK for
them to use it. Once pressed, it should be disabled until the next
time it's OK to use it. You may also have an 'Undo' button, in which
case I can think of no circumstance where they should both be enabled
at the same time - either one, or the other but never both. Remember
that you have to move the focus off the button in order to disable it.
In Your final sentence, you have hit on this same possibility!
You may care to consider that the 'Save' button should be disabled in
the Form's Open event and in it's Current event. Also that the 'Undo'
button is not enabled until the record starts to be created. To stop
users using the 'X' close button in the Form's title bar, make the
Form's border style Dialog. The rule is to stop them doing what you
don't want them to do and only to allow them to do what you do want to
do!
Following on from your excellent advice re making a sequential reference
number by clicking a button, I have been giving this considerable thought
since you posted and have nearly cracked the problem..... but not quite!
What I've done:
Made a data entry form (Form1) which writes directly to the main table. It
opens only in Add mode (i.e. as a blank form) and most of the data is
available only as combo boxes, so there's little room for user
creativity.... I have taken off the control box on the title bar and done as
you suggested so that the save and undo controls are disabled when the form
opens.
The Undo button is enabled as soon as the first field is filled - I suppose
I should add the enable code to all the fields in case they start filling it
in backwards or something? Is this something that could be on Form's
AfterUpdate event?
The other buttons are not enabled until they click on a button which
confirms that the form is finished and correct....
but this has presented a difficulty.....
The other buttons are:
1. Save Current and Add another record.... this uses the code you gave me to
give the record a unique number (which it doesn't display on this form)
which has been pasted in to the wizard's Add Record button. This works: it
updates the serial number in the table, and then clears the form for a new
entry
2. Save Current and Exit. This also works: it updates the serial number and
exits.
3. Undo current - this seems to work.
4. Exit without saving - Is there a neat way of doing this? I ended up
making a wizard's delete button, copying the OnClick event code and pasting
it into a wizard's exit button. This works, but it was actually making a
record and then deleting it so the AutoNumbers on the primary key had gaps
in the sequence (solved that by changing it to ReplicationID, so no-one will
ever know!) I have not added the number-generating code to this, so it
doesn't interfere with the sequence.
But....These four buttons all remain enabled if either the Undo or Save &
Add buttons are used, so it is possible to save an incomplete or incorrect
record ... a couple of the fields can't be 'required' because there isn't
always data to go in them, and I also have a checkbox which enables two
other fields if it is ticked, and if it is ticked in one form, those fields,
like the buttons remain available in the next.
I've tried adding the disabling code to other form events, but so far
haven't found an appropriate one. I am tempted to force a Save & Exit every
time, and have the user click on the switchboard button to add another
record, but it seems very clumsy to me.
In order to view/edit records, I've made a query and then bound another
form, Form2 to that. This has no save button at all, and most of the fields
which were completed in Form1, (including displaying the number Form1 made)
but there are a couple which might have to be changed and space to add notes
at a later date. This seems to work in that it saves these alterations in
the original record and cannot change the reference number or add a new
record - or delete one either.
fflei