Controlling order of data entry

D

Dave G

In an A2003 application I have a large TAB control with 10 pages. On a
couple of those pages are a series of date fields where I want to
ensure that they are filled in in order - in other words a user cannot
enter a date into a field until the one before it has data in it.

Now I can see a number of long winded ways to do this - but I'm
wondering if there is a slick way using a minimum amount of code,
hopefully a single fragment - perhaps using the tab order. I think I
need a way of tagging which fields are involved because not all fields
are - but that's where I'm stuck.

Any ideas gratefully received
Thanks
Dave
 
A

Allen Browne

It would be possible to cancel the BeforeUpdate event of each control if any
of the prior controls lack a value. The code would be along the lines of:
If IsNull(Me.Date1) Then
Cancel = True
strMsg = strMsg & "Date1 can't be blank." & vbcrlf
End If
'repeat for all the other controls
If Cancel Then MsgBox strMsg

But it seems likely there is something wrong with the schema here:
a) As far a possible, you try to create tables that do not have dependencies
between fields, and

b) If you have lots of dates in this record, you might need to create a
related table where there can be many *records* related to this one (one
record for each date), instead of lots of date fields in this record.
 
D

Dave G

Thanks Allen

I wish !!! Unfortunately I inherited this application, particularly
the data structures, and although I'd love to do it differently, I'm
stuck with it.

Sometimes when I write loads of repetitive code I think there must be
a better way but by the time I find out what that is I might as well
just do it the long way - at least I know it will work.

Well here's a clasic example where I thought I would try and do it in
a more cunning way and save a whole load of boring and fiddly coding.

Still looking
Dave
 
A

Allen Browne

Okay if you are comfortable with coding, can't change the data structure,
and must handle heaps of dependent controls, you could write a function that
accepts a Cancel argument (integer), message argument (string), and a
ParamArray (list of the controls that must be filled in before this one can
be.)

The function loops through the names in the ParamArray, and if any one is
true, it sets Cancel to True and concatenates the message to the string.

The BeforeUpdate of each control calls the func, passing its own Cancel
argument, a string to collect messages from, and a comma separated list of
the names of the controls that must be filled in before this one can be
accepted.

ParamArray is needed because the number of dependent controls varies across
the controls that will call it.

HTH
 
Top