Stopping an error message from apearing

G

Guest

I have some code on a form that makes a certain label flash depending on the
value of a combo box using the BeforeUpdate event:

Private Sub cboTypeOfCall_BeforeUpdate(Cancel As Integer)
If cboTypeOfCall.Value = "Sales" Then
Call SALEScolour
End If
End Sub

Sub SALEScolour()
Dim i As Integer
For i = 1 To 6
If lblSALESColour.BackColor = 255 Then
lblSALESColour.BackColor = -2147483633
Else
lblSALESColour.BackColor = 255
End If
Call ColourChanger(0.4)
Next
End Sub

Sub ColourChanger(TickTime As Double)
Dim TimeNow As Double
TimeNow = Timer
Do While Timer < TimeNow + TickTime
DoEvents
Loop
End Sub

If I change the value of the combo box before the lable has finished
flashing I get the following error.:

"The macro or function set to the BeforeUpdate or ValidationRule property
for this field is preventing DB1 from saving data in the field.

* If this is a macro, open the macro in the Macro window and remove the
action that forces a save (for exemple, GoToControl).
* If the macro inclides a SetValue action, set the macro to the AfterUpdate
property of the control instead.
* If this is a function, redefine the function in the Module window."

I have tried putting OnError events on all the related functions but none of
them will overide this error message appearing. How do I stop this happening?
--
Adam Thwaites
Access Database Designer
adam.*spamless*[email protected]
Manchester, UK
(I have no access to other sites apart from microsoft.com so posting
external links is no use to me)
 
D

Douglas J Steele

Any reason why that code's in the BeforeUpdate event? Typically you only put
code there that could result in the value not being accepted (you set Cancel
= True if the value's no good).

Try putting your call to SALEScolour in cboTypeOfCall_AfterUpdate.

You might also consider using the form's Timer event to do the flashing,
rather than having your own code. Simply set the form's TimerInterval to 400
(for .4 seconds), and put your colour change code in the form's Timer event:

Private Sub cboTypeOfCall_AfterUpdate()
If cboTypeOfCall.Value = "Sales" Then
Me.TimerInterval = 400
Else
Me.TimerInterval = 0
End If
End Sub

Private Sub Form_Timer()
If lblSALESColour.BackColor = 255 Then
lblSALESColour.BackColor = -2147483633
Else
lblSALESColour.BackColor = 255
End If
End Sub

To continue only allowing it to flash 6 times, you can use

Private Sub Form_Timer()
Static lngCount As Long

If lngCount = 0 Then
lngCount = 6
End If

If lblSALESColour.BackColor = 255 Then
lblSALESColour.BackColor = -2147483633
Else
lblSALESColour.BackColor = 255
End If

lngCount = lngCount - 1
If lngCount = 0 Then
Me.TimerInterval = 0
End If

End Sub
 
G

Guest

It's just the first one I found that fulflled my criteria of the code running
as soon as the cell was deselected.
--
Adam Thwaites
Access Database Designer
adam.*spamless*[email protected]
Manchester, UK
(I have no access to other sites apart from microsoft.com so posting
external links is no use to me)
 
G

Guest

Excellent, I switched the event to After Update and moved the code into the
timer event and now it's working fine. Thanks Douglas
--
Adam Thwaites
Access Database Designer
adam.*spamless*[email protected]
Manchester, UK
(I have no access to other sites apart from microsoft.com so posting
external links is no use to me)
 

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