Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to Automatically Run Code on Form_Current 1

Status
Not open for further replies.

gyli84

MIS
Aug 6, 2001
67
0
0
GB
I have the code:

Private Sub Form_Current()
If (Me!Priority1Limit) <= Me!Priority1Calls Then
Me!Priority1Calls.ForeColor = 255
Me!Label.Visible = True
Else
Me!Priority1Calls.ForeColor = 0

Me!Label.Visible = False
End If

End Sub

In the current event of a form. What I would like to know is how I could get this to run automatically without say attaching the code:

Form_Current

to the afterupdate event of the Priority1Limit textbox. What I want is for the code to run automatically each time the form is opened so that it will check whether the value in Priority1Calls is greater than that in Priority1Limit and if so it will change the colour of the Priority1Calls textbox and show a label

Thanks
 
You could create a sub-routine and make a call to this routine from the required events:

Sub setForeColour()
If (Me!Priority1Limit) <= Me!Priority1Calls Then
Me!Priority1Calls.ForeColor = 255
Me!Label.Visible = True
Else
Me!Priority1Calls.ForeColor = 0
Me!Label.Visible = False
End If
End Sub

Private Sub Form_Current()

setForeColour

End Sub
Private Sub Priority1Limit_Afterupdate()

setForeColour

End Sub
 
This still will not get the code to run automatically each time the form is opened. In fact for some strange reason if I type in a value in the Priority1Limit textbox lower than that in the Priority1Calls textbox it still does not run??? Is there something wrong with the code or does anyone know another way of achieving this text colour change effect and for the code to run automatically each time the form is opened, help!!!

Thanks
 
try formopen or formactivate.
You could also add me.repaint or me.refresh to the end of your code

HTH
Graham
 
Maybe I do not understand your problem, but what about the On Open or On Load events?
 
Hi!

Put string
Call setForeColour (accordingly theComeBackKid comment above) into AfterUpdate event's procedure of all needed controls eg.:
Private Sub Priority1Limit_AfterUpdate()
Call setForeColour
end sub


Aivars
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top