On Exit Code

  • Thread starter Thread starter jhicsupt
  • Start date Start date
J

jhicsupt

I have the event in "On Exit". However I want to add if Me.ColorStatus is
null, then [Forms]![Top 10].NGTColor is null. In other words, if user clears
Me.ColorStatus, then [Forms]![Top 10].NGTColor should also be clear.

Thanks in advance.

Private Sub ColorStatus_Exit(Cancel As Integer)
If Me.ColorStatus Like "Green" And Me.PRoduct Like "NGT*" Then
[Forms]![Top 10].NGTColor = "Green"
End If

If Me.ColorStatus Like "Yellow" And Me.PRoduct Like "NGT*" Then
[Forms]![Top 10].NGTColor = "Yellow"
End If

If Me.ColorStatus Like "Red" And Me.PRoduct Like "NGT*" Then
[Forms]![Top 10].NGTColor = "Red"
End If

End Sub
 
Hi,
Set up the variables to change the form's NGT color like this

Dim lngGreen As Long
Dim lngRed As Long
Dim lngYellow As Long

lngGreen = RGB(0, 255, 0)
lngRed = RGB(255, 0, 0)
lngYellow = RGB(255, 255, 0)

Assuming NGTcolor is a control, you can set its back color like this
--> [Forms]![Top 10].NGTColor.BackColor = lngGreen


Jeanette Cunningham
 
Thanks for quick reply. I actually want the words "Red", "Yellow", or
"Green" to stay in the form. That part is working fine. However, when the
user changes the subform that houses Me.ColorStatus to blank (nothing), then
I want the Mainform's field [Forms]![Top 10].NGTColor to be null. Hope this
is not too confusing.
 
Not sure I'm understanding your question, but here goes ...
Assuming NGTColor is a text box:

If Not IsNull(Me.ColorStatus) Then
If Me.ColorStatus Like "Green" And Me.PRoduct Like "NGT*" Then
[Forms]![Top 10].NGTColor = "Green"
End If

If Me.ColorStatus Like "Yellow" And Me.PRoduct Like "NGT*" Then
[Forms]![Top 10].NGTColor = "Yellow"
End If

If Me.ColorStatus Like "Red" And Me.PRoduct Like "NGT*" Then
[Forms]![Top 10].NGTColor = "Red"
End If
Else
[Forms]![Top 10].NGTColor = ""
End If


If you wish, the code can be simplified a bit like this:

If Me PRoduct Like "NGT*" Then
If Not IsNull(Me.ColorStatus) Then
With Me.ColorStatus
If . Like "Yellow" Then
[Forms]![Top 10].NGTColor = "Yellow"
ElseIf . Like "Green" Then
[Forms]![Top 10].NGTColor = "Green"
ElseIf . Like "Red" Then
[Forms]![Top 10].NGTColor = "Red"
End If
End With
Else
[Forms]![Top 10].NGTColor = ""
End If
End If


Note the above code has not been tested, it might need a bit of tweaking


Jeanette Cunningham


jhicsupt said:
Thanks for quick reply. I actually want the words "Red", "Yellow", or
"Green" to stay in the form. That part is working fine. However, when
the
user changes the subform that houses Me.ColorStatus to blank (nothing),
then
I want the Mainform's field [Forms]![Top 10].NGTColor to be null. Hope
this
is not too confusing.

jhicsupt said:
I have the event in "On Exit". However I want to add if Me.ColorStatus
is
null, then [Forms]![Top 10].NGTColor is null. In other words, if user
clears
Me.ColorStatus, then [Forms]![Top 10].NGTColor should also be clear.

Thanks in advance.

Private Sub ColorStatus_Exit(Cancel As Integer)
If Me.ColorStatus Like "Green" And Me.PRoduct Like "NGT*" Then
[Forms]![Top 10].NGTColor = "Green"
End If

If Me.ColorStatus Like "Yellow" And Me.PRoduct Like "NGT*" Then
[Forms]![Top 10].NGTColor = "Yellow"
End If

If Me.ColorStatus Like "Red" And Me.PRoduct Like "NGT*" Then
[Forms]![Top 10].NGTColor = "Red"
End If

End Sub
 

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

Back
Top