If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > PC based Database Applications > Microsoft Excel > different time, different form

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-27-08, 17:17
MASANOVIC MASANOVIC is offline
Registered User
 
Join Date: Jun 2008
Posts: 4
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?
Reply With Quote
  #2 (permalink)  
Old 07-01-08, 01:28
sco08y sco08y is offline
Registered User
 
Join Date: Oct 2002
Location: Baghdad, Iraq
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.

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.)
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On