2 questions

  • Thread starter Thread starter mm
  • Start date Start date
M

mm

Hi, I have two questions about coding in forms.

Q1. I have an unbound text box and I want to program it so
that it displays random numbers. I have =Rnd() and that
produces only fractional values like 0.0987. How can I
program it so that it takes a different form, like a long
positive integer with 5 digits (like 20988)?

Q2. I also have another unbound text box that I want to
use to display a message if a person's status is close to
expiring. So there is an original date on the form and an
expiration date. I want the text box to read the
expiration date and if that date is 6 months away from the
current date then it displays a message like "status is
about to expire". I have tried something like =iif([Text2]
=(date()-185), "Status is about to expire") but it did not
work. Text2 refers to the expiration date on the form. How
would I program the textbox to do that?

Thanx!!!!
 
Q1. When using the Rnd() function to create random
numbers, it always generates random between 0 and 1.
Multiply the result by a number to increase your random
number to the range you want. For instance, Int(Rnd()
*1000) will give you a higher number. Experiment with a
few numbers to see your results.

Q2. You need to use the DateDiff() function to compare
dates. Here's what should work.
strMessage = If DateDiff("m", now(), ExpireDate) <
7, "About to expire.", "")
 
Hi, I have two questions about coding in forms.

Q1. I have an unbound text box and I want to program it so
that it displays random numbers. I have =Rnd() and that
produces only fractional values like 0.0987. How can I
program it so that it takes a different form, like a long
positive integer with 5 digits (like 20988)?

Try CLng(10000. * Rnd(0)
Q2. I also have another unbound text box that I want to
use to display a message if a person's status is close to
expiring. So there is an original date on the form and an
expiration date. I want the text box to read the
expiration date and if that date is 6 months away from the
current date then it displays a message like "status is
about to expire". I have tried something like =iif([Text2]
=(date()-185), "Status is about to expire") but it did not
work. Text2 refers to the expiration date on the form. How
would I program the textbox to do that?

Well, a textbox won't "read" anything. I'd put code in the Form's
Current event to check:

Private Sub Form_Current()
If DateAdd("m", 6, Date()) > NZ(Me!txtExp, #12/31/9999#) Then
MsgBox "Status will expire on " & Me!txtExp
End If
End Sub
 
Back
Top