Creating 'flashing' form controls - problem with code (1 Viewer)

CarolW

Registered User.
Local time
, 21:02
Joined
Mar 24, 2006
Messages
58
Hello everybody,
Could anyone out there please help me with a small coding problem that I am experiencing....

I have a calculated control on my startup form called txtCurrentAge on which I have put VB code in the on-timer event of the form which makes the control 'flash on & off' if the persons age is below 18.
code as follows:


Private Sub Form_Timer()
If Me.txtCurrentAge.Value < 18 Then
Me.txtCurrentAge.Visible = Not Me.txtCurrentAge.Visible
Else
Me.txtCurrentAge.Visible = True
End If

End Sub

Everything works fine but when a user inadverently clicked on the control by mistake it caused the following error to be displayed: Runtime error 2165 "you cant hide the control that has the focus". What does this mean and how best could I prevent this from happening again as I cant guarantee that any of my users wont click on it again?? The text box concerned has been made 'visible', has not been 'locked' and is 'enabled'.
'
I find this 'flashing action' to be very useful and would like to keep it on my form....

I have searched on this site and various others but have been unsuccesful....

Any help or guidance would be very much appreciated.
P.S I obtained this code via databasedev.co.uk and adapted it to suit my particular DB.

Best Regards

CarolW
 

Matt Greatorex

Registered User.
Local time
Today, 00:02
Joined
Jun 22, 2005
Messages
1,019
I could be wrong - and I'm sure one of the more experienced bods will point it out if I am ;) - but I think the message relates to the fact that when the control is not selected (i.e. does NOT have focus), it can be hidden, so everything is fine. However, when it is selected (i.e. HAS focus), it cannot be hidden, so you get the message.

Does that make sense?
 

Sergeant

Someone's gotta do it
Local time
Today, 00:02
Joined
Jan 4, 2003
Messages
638
Just make this the first line of your sub...
Me.[SomeOtherControlName].SetFocus
 

jkl0

jkl0
Local time
Today, 00:02
Joined
Jun 23, 2006
Messages
192
Try changing you code to this to add error handling to you subroutine.

Private Sub Form_Timer()
On Error Goto Err_Form_Timer

If Me.txtCurrentAge.Value < 18 Then
Me.txtCurrentAge.Visible = Not Me.txtCurrentAge.Visible
Else
Me.txtCurrentAge.Visible = True
End If

Exit_Form_Timer:
Exit Sub

Err_Form_Timer:

If Err.Number = 2165 Then
Me.AnotherTextBox.SetFocus
‘(Or handle it some other way)
Exit Sub
End If

MsgBox Err.Description
Resume Exit_Form_Timer

End Sub

Hope this helps?
 

CarolW

Registered User.
Local time
, 21:02
Joined
Mar 24, 2006
Messages
58
Flashing form controls - problem solved..

jkl0 said:
Try changing you code to this to add error handling to you subroutine.

Private Sub Form_Timer()
On Error Goto Err_Form_Timer

If Me.txtCurrentAge.Value < 18 Then
Me.txtCurrentAge.Visible = Not Me.txtCurrentAge.Visible
Else
Me.txtCurrentAge.Visible = True
End If

Exit_Form_Timer:
Exit Sub

Err_Form_Timer:

If Err.Number = 2165 Then
Me.AnotherTextBox.SetFocus
‘(Or handle it some other way)
Exit Sub
End If

MsgBox Err.Description
Resume Exit_Form_Timer

End Sub

Hope this helps?

Matt Greatorex,Sergeant & jkl0.......
Thank you ever so much for helping me out. I followed your advice and came out trumps with a workable solution on both occasions.
Once again this forum has helped me solve my problems and as such I cannot
thank everyone enough for your guidance and Access wisdom.

Best Regards

Have a nice weekend...

CarolW
 

Users who are viewing this thread

Top Bottom