A command button which populates several fields with random values?

  • Thread starter Thread starter Mark Gifford
  • Start date Start date
M

Mark Gifford

Hi,

Can anyone point me in the right direction. Basically I have a
continuous form which retrieves many values from a table, and each of
the values is a number from 1 to 100. I also have two other fields
from the same table which essentially are for setting the min and max
boundaries for all the other values. For example:

minValue maxValue Value1 Value2 Value3 Value4
12 57 13 45 24 57
65 99 78 76 98 78 etc...

So Values 1-4 should never be outside of the range set by minValue and
maxValue. What I'd like is to create a command button beside each
record on my form which, when pressed, populates (or repopulates,
depending upon whether a value was present in the first place) the
Values 1-4 fields with random values that are between min and max
Values. Hope that makes sense. If anyone can give me a few solutions
or tips I'd be grateful.

Thanks

Mark
 
Mark,

The command button should run a piece of code like:

Randomize
Dim lv, hv, ctrl
lv = Me.MinValue
hv = Me.MaxValue
For i = 1 To 4
ctrl = "Value" & i
Me.Controls(ctrl) = Int(Rnd() * (hv - lv) + lv)
Next

This assumes that the control names on the form are the ones in your
posting, otherwize wou'll have to change accordingly.

HTH,
Nikos
 
Back
Top