Results 1 to 2 of 2
  1. #1
    Join Date
    Jun 2008

    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. #2
    Join Date
    Oct 2002
    Baghdad, Iraq
    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.

    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.

    Since your forms are labeled 1 through 4, I add 1.

    (Since I haven't test it, you'll have to and there's probably a bug. You can replace Date() and Time() with dates formatted like #mm/dd/yyyy# and times as #h:mm am# so you don't have to futz with your system clock.)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts