Clear alert on a timer

When an user is entering data in a form there are some logical errors that may occur.  These are not serious until the ‘Save’ button is clicked.  I would like to advise the user by the way of a gentle alert that there is a problem.

For example if the cost is 10 and the charge is 9 then there is a problem that needs addressing.

So I have created a label that is normally not visible.  The caption on the label is then set to explain the problem i.e.

Me.lblAlert.Caption = “Cost is higher than charge”
Me.lblAlert.Visible = True
DoCmd.Beep

… but I would like to clear the alert after a few seconds with:

Me.lblAlert.Visible = False

I am not sure how long to leave the alert visible but I can experiment.

Does anyone have some timer code that would achieve this please?
MikeDTEAsked:
Who is Participating?
 
mbizupCommented:
Hi Mike,

Not quite...

This goes in the form Timer event (not the load event).  The timer event gets fiered at whatever interval is specified either in the property sheet or through code.

Private Sub Form_Timer()
    Me.lblAlert.Visible = False
    Me.TimerInterval = 0   '<--- turns off the timer
End Sub

Open in new window


And this goes wherever you need to make this label visible - you want to start the timer as soon as the label is made visible, so that the label gets 'turned off' after 10 seconds:

Me.lblAlert.Caption = “Cost is higher than charge”
Me.lblAlert.Visible = True
DoCmd.Beep
Me.TimerInterval = 10000

Open in new window


0
 
mbizupCommented:
Place a value of 10000  in your Timer Interval property (this is measured in milliseconds, so that is 10 seconds).

Then in the Timer Event, add the following:

Me.lblAlert.Visible = False
Me.TimerInterval = 0   '<--- turns off the timer


You will also need code added to whatever event displays the label to set the timer:

Me.lblAlert.Caption = “Cost is higher than charge”
Me.lblAlert.Visible = True
DoCmd.Beep
Me.TimerInterval = 10000
0
 
mbizupCommented:
Actually - skip the part about adding the 10000 to the property sheet.   You don't want this to happen automatically when the form opens; you just want it to happen when your code triggers it.
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
MikeDTEAuthor Commented:
Hi mbizup

Good to hear from you again

I do not have any specific code to set the label as not visible - I just set the property in the designer to 'Visible=No'.

So would I add

Me.lblAlert.Visible = False
Me.TimerInterval = 0   '<--- turns off the timer

in Form_Load

and then

Me.lblAlert.Caption = “Cost is higher than charge”
Me.lblAlert.Visible = True
DoCmd.Beep
Me.TimerInterval = 10000

in the _AfterUpdate  

Just checking to see if I got it right!

0
 
MikeDTEAuthor Commented:
Hi mbizup

Just tried out the code as I had assumed it would be inserted ... but it doesn't work

The line 'Me.TimerInterval = 10000' has no affect at all!

Is there not a timer function to add somewhere?

Also the DoCmd.Beep is conspicuous by it's silence

Regards
Mike
0
 
Dale FyeCommented:
Mike,

Yes, you need to add same code you have in the form_load event to the Timer event:

Private sub Form_Timer

    Me.lblAlert.Visible = False
    Me.TimerInterval = 0   '<--- turns off the timer

End Sub
0
 
mbizupCommented:
<< Also the DoCmd.Beep is conspicuous by it's silence >>

Really?  I'm not sure why you don't hear a sound - it makes a short, low 'beep' here...
0
 
MikeDTEAuthor Commented:
Thanks mbizup

Original problem resolved - timer working faultlessly - the points are yours.

Beep still missing at this end - I'll do some browsing and see if anybody else has a silent (and deadly) beep!

Regards
Mike

0
 
MikeDTEAuthor Commented:
Excellent answer - thanks
0
 
mbizupCommented:
Glad that worked out!

Not sure about your beep() issue...

Both of these are alternatives for making sounds:

msgbox "Beep",vbexclamation
msgbox "Beep",vbCritical

But they might not fit in well with what you are doing.

0
 
Dale FyeCommented:
The problem with the Beep is that you cannot control the volume, so if your volume is turned way down, and there are noises around you, or you are playing your Internet radio, you could very well not hear the beep.

I generally prefer to pop-up a  message box, which displays a specific message and the places the cursor back in the appropriate control.  The msgbox will not go away until manually cleared, and forcing the focus back to an offending value just makes sense.  Otherwise, they have to read your message, understand it, and move the focus back to the offending control on their own.
0
 
MikeDTEAuthor Commented:
Hi fyed

Thanks for your observations.  The msgbox method was considered, tried and rejected as too clumsy.  The subtle prompt achieved by the appearance of a label and it's timed clearance is much more appropriate in this case.

The beep - the volume was the problem.  Interestingly I can't get to the volume properties but all my multimedia sounds work - music CD's, DVD soundtracks, internet radio etc. all work.  System sounds (the Windows Default sound scheme is enabled) do not work.  This is a problem with my PC but that will not be the case on the client's systems.  So hey! I can live without the beeps.

Regards
Mike
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.