Hi,
There is a point where building a universal good to every possible cases
machine is just too expensive. In most of the cases, some of the logic would
be hard-coded. As example, if your form can handle trucks and planes, then
selecting a truck or a plane may allow to further enter a GrossWeight
value, but if a truck is being "selected" , the WingSpan value makes no
sense. So, assuming someone start entering data for a truck, then the
WingSpan control may become disabled, and the logic may be hard coded with a
Select case statement in the AfterUpdate even of the combo box allowing to
choose a plane or a truck:
Select case Me.ComboBoxName.Value
Case "Plane"
Me.WingSpan.Enabled = True
Me. .. ' other controls, if applicable
Case "Truck"
Me.WingSpan.Enabled=False
...
End Select
You can also repeat the same code (or Call the same subroutine) in the
onCurrent event too, since you probably want the same behavior when the end
user comes back to look at the data already entered.
Hoping it may help,
Vanderghast, Access MVP
Ezekiël said:
In your example is also appplyable when i want certain controls on a form
disabled.
E.g. in the beforementioned table someone may choose a value from a combobox
and when that value is choosen, the validation of a field may change and
other controls are enabled/disabled.
How can i solve a situation like this.
Michel Walsh said:
Hi,
Modifying data in a table is standard process, while modifying any
constant in a SELECT CASE requires access to the code. Furthermore,
data
is
better stored in a data storage (table, file) than in code.
Hoping it may help,
Vanderghast, Access MVP
Is it better to do it in a table rather then in an array with select
statement?.
Hi,
We could do that through a table.
Validations ' table name
CaseOf BetweenThis AndThat ' fields name
A 100 1000
B 0 100
... 'data
YourTable ' table name
CaseOf Qty ' fields name
Then, in a query,
SELECT yourtable.*, Validations.*
FROM yourTable INNER JOIN Validations
ON yourtable.CaseOf = Validations.CaseOf
and then, you could test
If rst("Qty") < rst("BetweenThis") OR rst("Qty") >=
rst("AndThat" )
Then
... failure... Qty is not in the range [BetweenThis] and
[AndThat]
assigned to its values of "CaseOf" in
table
Validations.
End If
It may even be easier to visualize the correlation between the
data
just
seeing the query in its "data view".
Hoping it may help,
Vanderghast, Access MVP
Hi everyone,
Does somebody has a good example how to use an array with select case
statement.
For example, i have a lookup table with values like A, B, C, etc.
If someone chooses a value in a form's combobox then the value should
be
evaluated in a select statement.
For example:
Select case cmb1
case "A"
validation in some field's property must be >=100
case "B"
same as above but then <=100
etc.
What i would like is not to hardcode the values in the select
statement,
but
rather use an arrayvalue to put next the case line. The array should
use
it
values from the lookup table.
How can i achieve this?