Discussion Locked

func of time in msaccess or vb prog

0 helpful
9 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.
Is there a direct function for diplaying the time of cmos (or just the windows time) to an ms access program? how about on VB? if there is no direct funtion, is there a way to manipulate it. I just wanted a form that displays the current time, like a digital clock. cause i'm trying to make a login/logout database and i want the time to be displayed always.

9 replies

by tom

Insert =Time() into a text box or label
then refresh the box every sec or so

by mbarker734

On your form create a text box. Set the control source of this text box to: =Time()

This set the text box to system time.

Create an event procedure in the On Timer area of the form. Place this line in the event: me.refresh

Every time the event procedure is called the code will be run and refresh the display.

In the Timer Interval of the form place the number: 500

The Timer Interval is the number of miliseconds that will pass before the On Timer event will occur.

You may have to adjust this number dependant upon your processor speeds but, you can cause it to the Timer Interval to be near one second.

I would also suggest setting the tabs so that the text box is not the active control on the form. This will provide for a less flickering effect.

Good luck,

Mark

by mpdcsup

In addition to Now(), you will find Format() useful in formatting the display.

Rather than a bound control, I would use a label to display the time.

Create a timer control (or for Access 97, use the Form_Timer Sub) and set the Timer.Interval (or Form.TimerInterval for '97) to 1000 milliseconds (1 second).

In the Sub handling the timer event, excute the following line:

MyLabel.Caption = Format(Now(), "hh:nn:ss")

In the Table definition add the field for your CurrentTime and set the default value to =Now()

Don't bother trying to save the date/time from the form to the database (the default will take care of giving the record an appropriate date/time value when the record is created).

This discussion is closed to new replies.