# Thread: different time, different form

1. Registered User
Join Date
Jun 2008
Posts
4

## Unanswered: different time, different form

I would like to know if this is possible. I want to create 4 different forms. I want 1st form to open from a command button. Then 12 hours later, if you click the button form 2 opens. then 12hrs later form 3 would open, 12 hours later form 4. Then after 12 further hours back to form 1. And keep looping around.

Can this be done?

2. Registered User
Join Date
Oct 2002
Location
Posts
697
Sure... I don't have Access in front of me, but use the wizard to cook up a command button that opens Form1. View the source code and you'll see fairly plainly where the form name is; it's just a string.

Code:
```dim num as integer
num = (DateDiff("d", Date(), #1/1/1970#) Mod 2) * 2 + Iif(Hour(Time()) > 12, 1, 0) + 1
formname = "Form" & num```
Then you just drop formname in where it fits. It'll be something like DoCmd.OpenForm

How it works: the datediff function counts the number of days (due to "d" as the first parameter) between todays date and Jan 1, 1970 (the earliest date Access knows of). We want to know if that number is even or odd. You can look up the help for the Mod operator, but in a nutshell, x Mod 2 returns 0 if x is even and 1 if x is odd.

Multiply that by 2 and we get either 0 or 2. Next we want to know if it's before noon or after noon, so we get compare 12 to the hour of the current time and add 1 if it's after noon. Now we have a number 0, 1, 2 or 3 that will increase every twelve hours.