What is the best way to set up control validations?

J

Jon A

I have a main form with about 20 controls: text and combo
boxes for data input, buttons for performing user actions,
and some text boxes for information display (no input, such
as a display of the current record's status or some
calculations based on data displayed in other controls on
the current record).

I have a subform with similar number and type of controls.

The display of each of the controls is dependent on a number
of other data elements or controls. For example, there are
several buttons to Accept, Return, Close, or Cancel an Order
based on several things taken together, such as the
OrderStatus, whether the OrderReview has been performed, a
validation of the data elements on the Order, etc. So based
on the various combinations that are possible, the action
buttons are enabled or disabled, combo boxes have their
RowSource set to the appropriate query, text boxes and
combos are visible/enabled or not, etc.

That's one example of a few of the controls, but I think it
gets across the background for my issue/question.

I have set up subprocedures that get called to appropriately
set the state of each of these controls. So far I have
gotten them all working OK.

My question/issue is more one of effective, elegant, and
efficient programming. I have placed Debug.Print statements
at the head of each of the procedures. All the statement
does is print to the Immediate window the procedure name.
This is just to do a trace of what happens when anything
occurs, such as clicking on an action button or going to a
new record.

I have noticed that all these validation and state-setting
procedures sometimes get called twice when something occurs
(not every time, just sometimes).

For example, when I go to a new record all the procedures
are called because we get a Form_Current event. Then
Form_Current executes a second time and everything gets done
all over again.

As another example, if I click on an action button or select
a dropdown, the subprocedures get called according to the
AfterUpdate event or the Button_Click event, and then
Form_Current seems to run again and calls everything all
over again.

I figured I had to call all the subprocedures from
Form_Current because that covered the situation when the
form is first opened as well as when going to a new record.
I haven't been able to get things to work correctly if I put
the procedure calls anywhere else.

Now, functionally everything works OK. But having noticed
this, I am wondering if maybe I have set things up
incorrectly? Is there some other way to design the logic
behind the procedures, or do I just have to put up with
this?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top