Placing a random number in unbound textbox

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I created a textbox (txtPoints) and want the form to enter a random number from 1 - 9 in the box when the form opens

I tried to use this formula in the textbox OnDirty event
Dim MyValu
MyValue = Int((9 * Rnd) + 1

but it didn't work. I really don't care how the number gets into the box, but I want to use it as a game on the forms

Any Ideas

Thanks As Always
RIP
 
A textbox doesn't have an OnDirty event. A form does, but I don't see where
you are assigning the value to the text box, just a variable. Try assigning
MyValue to a textbox:

Dim MyValue
MyValue = Int((9 * Rnd) + 1)
Text4 = MyValue

Of course this will only trigger if you dirty the form, that is change or
enter some value. Is this when you really want it to happen?

--
--Roger Carlson
www.rogersaccesslibrary.com
Reply to: Roger dot Carlson at Spectrum-Health dot Org

Ripper said:
I created a textbox (txtPoints) and want the form to enter a random number
from 1 - 9 in the box when the form opens.
I tried to use this formula in the textbox OnDirty event:
Dim MyValue
MyValue = Int((9 * Rnd) + 1)

but it didn't work. I really don't care how the number gets into the box,
but I want to use it as a game on the forms.
 
What I really want is to have a random number appear in the that unbound textbox when the form opens

Rip
 
When it opens or when you move to a new record? the OnOpen event will work
when the for first opens, and the OnCurrent event will work for both.
 
Add the following to the textbox's DefaultValue property:
=Int((9 * Rnd()) + 1)

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia


Ripper said:
I created a textbox (txtPoints) and want the form to enter a random number
from 1 - 9 in the box when the form opens.
I tried to use this formula in the textbox OnDirty event:
Dim MyValue
MyValue = Int((9 * Rnd) + 1)

but it didn't work. I really don't care how the number gets into the box,
but I want to use it as a game on the forms.
 
Back
Top