Randomly Date Increase - Decrease

Anthony George

Registered User.
Local time
Today, 19:29
Joined
May 28, 2004
Messages
105
Hi Everyone

I have a program that has an end date field called MyEndDate. It is formatted as a short date dd/mm/yyyy

Does anyone know a way that i can return this date after being randomly increased or decreased by 6 days either way, into another variable called MyEndDateRandom.

Ive tried doing it with normal random number generators but it just seems to concatenate the year 2008 into something like 20086.

Thanks for any help

Kindest Regards

Tony
 
Do the adding or substracting before you reformat it to a string.... You can add 6 days to a normal date without any problems

Lookup the dateadd function.
 
Great advice from the Mailman

Hi Mailman

Thanks for pointing me in the right direction.
I ended up with this and it works just great:-

LRandomNumber = Int((6 - 1 + 1) * Rnd + 1)
Me![MyEndDateRandom].SetFocus
Me![MyEndDateRandom].Text = DateAdd("d", LRandomNumber, [Myenddate])

Thanks again my friend

Kindest regards

Tony
 
I think it goes something like this

Hi Mailman

I think it's to maintain the correct syntax for the Rnd function

In Access, the Rnd function allows you to generate a random number (integer value). You can specify the random number to be a value between 2 user-specified numbers.

The syntax for the Rnd function is:

Int ((upperbound - lowerbound + 1) * Rnd + lowerbound)

upperbound is the highest value that the random number can be.

lowerbound is the lowest value that the random number can be.

For example:

Int ((6 - 1 + 1) * Rnd + 1) would return a random number between 1 and 6.
Int ((200 - 150 + 1) * Rnd + 150) would return a random number between 150 and 200
Int ((999 - 100 + 1) * Rnd + 100) would return a random number between 100 and 999

I think that's how it works

If I remember correctly, I got it off the net somewhere in the past.

Regards

Tony
 

Users who are viewing this thread

Back
Top Bottom