'Flashing' data

G

Guest

I have set the following control on the 'timer' event:
Private Sub Form_Timer()
With Me.[um_lab]
.ForeColor = (IIf(.ForeColor = vbRed, vbBlack, vbRed))
End With
End Sub
In the 'current' event I have this:
Private Sub Form_Current()
If Me![um_lab].<NOW() Then
Me.TimerInterval = 300
Else
Me.TimerInterval = 0
Me.[um_lab].ForeColor = vbBlack
End If
End Sub

The result is red/black flashing data in the 'um_lab' text box when the
date in there is less than todays.
I wish to duplicate this in a second field (um_part), but I get errors when
I duplicate
the code and just change the names.
Can I put a 'list' in the code of text boxes that will be changed by the
settings, or do I have to put a seperate entry for each text box?

tia.
 
M

Marshall Barton

Jock said:
I have set the following control on the 'timer' event:
Private Sub Form_Timer()
With Me.[um_lab]
.ForeColor = (IIf(.ForeColor = vbRed, vbBlack, vbRed))
End With
End Sub
In the 'current' event I have this:
Private Sub Form_Current()
If Me![um_lab].<NOW() Then
Me.TimerInterval = 300
Else
Me.TimerInterval = 0
Me.[um_lab].ForeColor = vbBlack
End If
End Sub

The result is red/black flashing data in the 'um_lab' text box when the
date in there is less than todays.
I wish to duplicate this in a second field (um_part), but I get errors when
I duplicate
the code and just change the names.
Can I put a 'list' in the code of text boxes that will be changed by the
settings, or do I have to put a seperate entry for each text box?


One approach to dealing with a "group" of controls is to set
their Tag property to something indicative such as FLASH.
Then the code would be:

Private Sub Form_Timer()
Dim ctl As Control
For Each ctl In Me.Control
If ctl.Tag = "FLASH" Then

ctl.ForeColor=IIf(ctl.ForeColor=vbRed,vbBlack,vbRed)
End I
Next ctl
End Sub

Private Sub Form_Current()
If Me![um_lab] < Date Then
Me.TimerInterval = 300
Else
Me.TimerInterval = 0
For Each ctl In Me.Control
If ctl.Tag = "FLASH" Then
ctl.ForeColor = vbBlack
End If
Next ctl
End If
End Sub
 
G

Guest

Marshall,
That works ok up to a point.
Where the dates in both fields (um_lab & um_part) are the same, things flash
as would be expected. When the dates differ and one date is before today's
date and one falls after, then they both flash, where only the one falling
before today's date should flash.

Thanks,
--
Jock Waddington


Marshall Barton said:
Jock said:
I have set the following control on the 'timer' event:
Private Sub Form_Timer()
With Me.[um_lab]
.ForeColor = (IIf(.ForeColor = vbRed, vbBlack, vbRed))
End With
End Sub
In the 'current' event I have this:
Private Sub Form_Current()
If Me![um_lab].<NOW() Then
Me.TimerInterval = 300
Else
Me.TimerInterval = 0
Me.[um_lab].ForeColor = vbBlack
End If
End Sub

The result is red/black flashing data in the 'um_lab' text box when the
date in there is less than todays.
I wish to duplicate this in a second field (um_part), but I get errors when
I duplicate
the code and just change the names.
Can I put a 'list' in the code of text boxes that will be changed by the
settings, or do I have to put a seperate entry for each text box?


One approach to dealing with a "group" of controls is to set
their Tag property to something indicative such as FLASH.
Then the code would be:

Private Sub Form_Timer()
Dim ctl As Control
For Each ctl In Me.Control
If ctl.Tag = "FLASH" Then

ctl.ForeColor=IIf(ctl.ForeColor=vbRed,vbBlack,vbRed)
End I
Next ctl
End Sub

Private Sub Form_Current()
If Me![um_lab] < Date Then
Me.TimerInterval = 300
Else
Me.TimerInterval = 0
For Each ctl In Me.Control
If ctl.Tag = "FLASH" Then
ctl.ForeColor = vbBlack
End If
Next ctl
End If
End Sub
 
M

Marshall Barton

Jock said:
That works ok up to a point.
Where the dates in both fields (um_lab & um_part) are the same, things flash
as would be expected. When the dates differ and one date is before today's
date and one falls after, then they both flash, where only the one falling
before today's date should flash.


Ahhh, I misunderstood what you wanted. It now looks like
the flashing controls are all date controls and each of the
date controls should flash independently of the others. If
that's what you want, try this:

Private Sub Form_Timer()
Dim ctl As Control
For Each ctl In Me.Controls
If ctl.Tag = "FLASH" And ctl < Date Then
ctl.ForeColor=IIf(ctl.ForeColor=vbRed,vbBlack,vbRed)
End I
Next ctl
End Sub

Private Sub Form_Current()
Dim ctl As Control
Me.TimerInterval = 0
For Each ctl In Me.Controls
If ctl.Tag = "FLASH" And ctl < Date Then
Me.TimerInterval = 300
Else
ctl.ForeColor = vbBlack
End If
Next ctl
End Sub

If your form has a lot of controls and the loop in the timer
event takes too long, then post back with more details and
I'll try to come up with a way to reduce the number of loop
iterations.
 
G

Guest

Hi Marshall,
I get a 'Object doesn't support this property or method' run time error and
the line 'If ctl.Tag = "Flash" And ctl < Date Then' is highlighted.
I have tried litle tweaks to try to get rid of this error, but I can't.
Any ideas?

regards,
 
J

John Spencer

Not Marshal, but you might try breaking the Line
If ctl.Tag = "FLASH" And ctl < Date Then
Into two tests.

The first test to see if the control's tag is equal to "Flash" and the
second to test the value of the control. The problem is that the line above
ALWAYS attempts to do BOTH tests. If ctl is a label, a line, or other
control that doesn't have a value, then the second test will generate an
error. If you nest the tests, as below, the second test only get executed
if the first test is true.

Private Sub Form_Timer()
Dim ctl As Control
For Each ctl In Me.Controls
If ctl.Tag = "FLASH" Then
IF ctl < Date Then
ctl.ForeColor=IIf(ctl.ForeColor=vbRed,vbBlack,vbRed)
End If
End If
Next ctl
End Sub
 
G

Guest

H(either prioi John,

With that code in place, if the date in 'A' is before today, while 'B' is
after, then data in both fields is black (ie not flashing). With that
criteria reversed, then 'B' flashes and 'A' remains black, which is correct.
When both dates are the same,(either both dates before today or both after)
then the result is correct, so we're almost there.

Many thanks,
 
J

John Spencer

Did you set the Tag property for both A and B to "FLASH"?

The code as posted will independently make the control A flash if it is
before todays date and will independently make control B flash if it is
before today's date.

I assumed that you also changed the test in the current event of the form.
Although I didn't specifically recommend that.

Jock W said:
H(either prioi John,

With that code in place, if the date in 'A' is before today, while 'B' is
after, then data in both fields is black (ie not flashing). With that
criteria reversed, then 'B' flashes and 'A' remains black, which is
correct.
When both dates are the same,(either both dates before today or both
after)
then the result is correct, so we're almost there.

Many thanks,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top