Timer delayed (5 seconds)

J

James C.

I have a login form that I have working just fine. When the user inputs their
name and password I have the information being check by my password function.
If the information inputted is correct I have a text box that pops up saying
"User X has succesfully logged in!"

I want to be able to have it wait there for 5 seconds before closing the
login script and opening my other form. Is there an easy way to do this in my
password function?

Thanks for any help
 
D

Dirk Goldgar

James C. said:
I have a login form that I have working just fine. When the user
inputs their name and password I have the information being check by
my password function. If the information inputted is correct I have a
text box that pops up saying "User X has succesfully logged in!"

I want to be able to have it wait there for 5 seconds before closing
the login script and opening my other form. Is there an easy way to
do this in my password function?

I'd use the Timer event of the form. After validating the login info,
you can make the text box visible and set the form's TimerInterval
property to 5000. At design time, you'd have built an event procedure
for the form's Timer event that closes the form and opens the other
form, but you'd have left the TimerInterval property set to 0 -- the
Timer event won't fire until you change that property to a non-zero
value and that number of milliseconds has passed.
 
J

James C.

Hi Dirk,

I guess that is what I need some help with. i know where the timer event is
in the form, but i don't know how (in code) to call that event. This is where
I am stuck. The premise behind it is to make the text box visible and then
set the timer to 5000 and then when it hits 5000 it will close the form and
open the other form. I just don't know how to do this in the code section.

Any ideas?
 
D

Dirk Goldgar

James C. said:
Hi Dirk,

I guess that is what I need some help with. i know where the timer
event is in the form, but i don't know how (in code) to call that
event. This is where I am stuck. The premise behind it is to make the
text box visible and then set the timer to 5000 and then when it hits
5000 it will close the form and open the other form. I just don't
know how to do this in the code section.

You don't normally call the Timer event directly -- that's the whole
point of it; it fires every (TimerInterval) milliseconds.

Open the form in design view. Open its property sheet (make sure you've
got the property sheet for the form, not for a control or section on the
form). Go to the Event tab. Find the line "On Timer". Click on that
line, then on the "build" button (caption "...") that wil appear at the
end of the line. If prompted, choose "Code Builder". You should be
presented with the shell of a Timer event procedure, which will look
like this:

Private Sub Form_Timer()

End Sub

Fill in that shell with code like this (adapted to suit your
circumstances):

Private Sub Form_Timer()

' Switch off the timer. Shouldn't need to do this,
' but just in case the other form takes a loooong
' time to open ...
Me.TimerInterval = 0

' Open the next form.
DoCmd.OpenForm "frmOtherForm"

' Close this form.
DoCmd.Close acForm, Me.Name, acSaveNo

End Sub

That will take care of the timer business. Now all you need to do in
your login validation code is, after you've verified that the login is
valid, execute these lines:

Me.lblOkayMessage.Visible = True
Me.TimerInterval = 5000

Substitute the name of your "successful login" message control for
"lblOkayMessage" in the above. I assumed it would be a label, since it
doesn't need to take input, but it could be a text box as you originally
stated.
 
J

James C.

This is perfect. Thanks for the help!!!!

Dirk Goldgar said:
You don't normally call the Timer event directly -- that's the whole
point of it; it fires every (TimerInterval) milliseconds.

Open the form in design view. Open its property sheet (make sure you've
got the property sheet for the form, not for a control or section on the
form). Go to the Event tab. Find the line "On Timer". Click on that
line, then on the "build" button (caption "...") that wil appear at the
end of the line. If prompted, choose "Code Builder". You should be
presented with the shell of a Timer event procedure, which will look
like this:

Private Sub Form_Timer()

End Sub

Fill in that shell with code like this (adapted to suit your
circumstances):

Private Sub Form_Timer()

' Switch off the timer. Shouldn't need to do this,
' but just in case the other form takes a loooong
' time to open ...
Me.TimerInterval = 0

' Open the next form.
DoCmd.OpenForm "frmOtherForm"

' Close this form.
DoCmd.Close acForm, Me.Name, acSaveNo

End Sub

That will take care of the timer business. Now all you need to do in
your login validation code is, after you've verified that the login is
valid, execute these lines:

Me.lblOkayMessage.Visible = True
Me.TimerInterval = 5000

Substitute the name of your "successful login" message control for
"lblOkayMessage" in the above. I assumed it would be a label, since it
doesn't need to take input, but it could be a text box as you originally
stated.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 
Top