If statement

  • Thread starter Thread starter Antonio
  • Start date Start date
A

Antonio

I have a form that displays in datasheet format. It
contains several fields, two of which are
called "SenderID" and "DateSent". I would like to change
the back color of both fields depending on what
the "SenderID" filed is currently displaying. I tried the
following if statement on the forms "On Current" event:

Private Sub Form_Current()
If Me.SenderID = "Admitted" Then
Me.SenderID.BackColor = vbRed
Me.DateSent.BackColor = vbRed
Else
Me.SenderID.BackColor = vbWhite
Me.DateSent.BackColor = vbWhite
End If
End Sub

However, when I save, compile, and open the form....the
back color both of the entire columns is Red vice just
the records whose SenderID field is "Admitted". I dont
know what I am doing wrong.
 
Hi Antonio

You cannot use Form_Current, for exactly the reasons you gave. It affects
the whole column.

In Access 2000 and later, you can use conditional formatting:

1. Select the SenderID text box.

2. Choose Conditional Formatting on the Format menu.

3. Enter you condition and choices of backcolor.

4. Do the same for the DateSent text box, but use Expression in the
Conditional Format. The expression will be:
[SenderID] = "Admitted"
 
Mr Brown,
Thank you so very much for your help. I had been
attempting to make this work for quite some time. Your
help is very much appreciated.

-----Original Message-----
Hi Antonio

You cannot use Form_Current, for exactly the reasons you gave. It affects
the whole column.

In Access 2000 and later, you can use conditional formatting:

1. Select the SenderID text box.

2. Choose Conditional Formatting on the Format menu.

3. Enter you condition and choices of backcolor.

4. Do the same for the DateSent text box, but use Expression in the
Conditional Format. The expression will be:
[SenderID] = "Admitted"

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Antonio said:
I have a form that displays in datasheet format. It
contains several fields, two of which are
called "SenderID" and "DateSent". I would like to change
the back color of both fields depending on what
the "SenderID" filed is currently displaying. I tried the
following if statement on the forms "On Current" event:

Private Sub Form_Current()
If Me.SenderID = "Admitted" Then
Me.SenderID.BackColor = vbRed
Me.DateSent.BackColor = vbRed
Else
Me.SenderID.BackColor = vbWhite
Me.DateSent.BackColor = vbWhite
End If
End Sub

However, when I save, compile, and open the form....the
back color both of the entire columns is Red vice just
the records whose SenderID field is "Admitted". I dont
know what I am doing wrong.


.
 
Back
Top