Current event does not work

G

Guest

I have a main form and a subform. The main form contains information of a
specific person, i.e., a student's name, stud's address, etc. This main form
simply pulls data from a table, so the user does not have to typing in the
data. The subform has textboxes that the user enters the students's scores.

There is a textbox to hold the sum of these scores, intTotal. After the user
entered the scores, one of these labels "A" or "B" or "C" or "D" will be
highlighted; i.e., RGB(0,255,0), depending on the scores. The problem is when
I advance to the next record using the Access built-in navigation on the
subform, the previous label of the previous record is still there. The same
problem happens when I click the next button on the navigation of the main
form. I did use the current event on the subform, but it seems does not work.
What should I do to clear the previous label because the next record's data
haven't been entered yet. Thank you for your helo - tim
 
G

Guest

Hi Doug:
In the OnCurrent event, I put some simple codes as following:
If IsNull(intTotal) Or intTotal = 0 Or intTotal = "" then
labelA.BackColor = RGB(0,0,0)
labelB.BackColor = RGB(0,0,0)
labelC.BackColor = RGB(0,0,0)
labelD.BackColor = RGB(0,0,0)
ElseIf intTotal >= 90 And intTotal <= 100 Then
labelA.backColor = RGB(0, 255, 0)
ElseIf intTotal >= 80 And intTotal <=90 Then
labelB.backColor = RGB(0,255,0)
---
and so on. If the intTotal falls into within a range then the corresponding
label will
be highlighted.

I don't know if there is a conflict between the main form and the subform. I
put the
code into the subform.
Thank you for your help in advance - tim
 
D

Douglas J. Steele

Once you've set labelA's backcolor to Green because intTotal is between 90
and 100, if the next value of intTotal is between 80 and 90, you're setting
labelB's backcolor, but not resetting labelA's. Try putting the 4 lines that
set the backcolors to RGB(0,0,0) outside of the check. (You might also
consider using a SELECT CASE statement, rather than a series of ElseIf
statements, but again, that's likely not the cause of your problems.)

Some other comments.

What is intTotal? Assuming it's been defined as an integer (as the name
implies), you don't need to check for IsNull (only variants can be Null),
and you don't need to check for "" (integer values can only hold numbers)

To make sure Access knows you're dealing with controls on the form, try
using Me.labelA.BackColor, Me.labelB.BackColor and so on.
 
G

Guest

Hi Expert,
Your explanation makes sense! I will add more lines of codes into the If
Else statements. I had used the Select Case before but I don't know why it
does not worked so I have changed to IfElse. I will let you know ...
Thank you very much
tim
 
G

Guest

Hi Expert,
I have tried both If/Else statements and Case/Select, but both won't work.
When I tested by entering the perfect scores (100), it does show up the
highligh color; however, when I tried the intTotal=80, nothing happened, just
white color. The code is following:

Me.Refresh
If Me.intTotal.Value = 0 Then
Me.lblA.BackColor = RGB(255, 255, 255)
Me.lblB.BackColor = RGB(255, 255, 255)
Me.lblC.BackColor = RGB(255, 255, 255)
Me.lblD.BackColor = RGB(255, 255, 255)
Else
Select Case intTotal
Case 96 To 100
Me.lblA.BackColor = RGB(255, 255, 0)
Case 88 To 95
Me.lblB.BackColor = RGB(255, 255, 0)
Case 80 To 87
Me.lblC.BackColor = RGB(255, 255, 0)
Case 72 To 79
Me.lblD.BackColor = RGB(255, 255, 0)
Case 65 To 71
Me.lblU65To71.BackColor = RGB(255, 255, 0)
End Select
End If
==========
Same thing with the If/Else statement, i.e., just the first scores (case 96
to 100) would work. Otherwise, no matter how many times I have tried, no
color will be showed up to highlight other scores. In the case of the If/Else
statement, I put 4 lines that set the backcolors to RGB(255, 255, 255)
outside of the check as you adviced.
Do you know why? Thanks, -tim
 

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