RXTypeID is on the many side of a one-to-many relationship; it can hold many values. Two compulsory values are RXTypeID = 2 and RXTypeID = 3. If one or both are not present, control must change color.
Main Topics
Browse All TopicsHi
Am trying to do conditional formatting on a form. Need to set a color on a form control if two values are not present. I cannot figure the expression. The values are RxTypeID = 2 and RxTypeID = 3. Both values have to be true, if not true then control changes color. How do I write this expression. Thank you
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
so, you might have several rows, and you have (at least) 2 rows, with the values 2 and 3, then put the control in green, otherwise in red?
based on which event do you want to check for the color? on form-load? on button-click?
is there some other value/control on the form, based on which you have to filter the rows to check for?
This is how it should work; control must change color if both ISFALSE(RxTypeID = 2) and ISFALSE(RxTypeID = 3).
If only one of the above is false, then that's ok because I have another condition set up to catch for one missing value.
In the conditional format tool I initially coded IsNull([RxTypeID])=True but this only partially works because if, in one record, RxTypeID = 1 and nothing else, the control does not color because now (IsNull([RxTypeID])=False.
Think I have described it correctly now
Thanks
>Should it be
>if (c2 > 0 and c3>0) then
yes, sorry for the typo
>OK, dont understand the Dsum("1",..)
DSUM("<field/value>", "<table/query>", "<condition>")
will return the same as if your run this query:
SELECT SUM(<field/value>) FROM <table/query> WHERE <condition>
in my suggestion, that would be:
SELECT SUM(1) FROM yourtable WHERE RxTypeID = 2
resp:
SELECT SUM(1) FROM yourtable WHERE RxTypeID = 3
so, if the sum returned is > 0, means that at least 1 record for that condition is in the table.
Have tried this, but getting "wrong number of arguments or invalid property assignment error" in the IsNull expression. Did the IsNull test because was getting a null error.
Am I on the right track?
Thanks
Private Sub Form_Current()
Dim c2 As Integer
Dim c3 As Integer
c2 = IIf(IsNull(Me.Requirement,
c3 = IIf(IsNull(Me.Requirement,
If (c2 > 0 And c3 > 0) Then Me.Requirement.BackColor = White 'both of the values exist
ElseIf (c2 > 0 Or c3 > 0) Then Me.Requirement.BackColor = White 'at least one of the 2 values exists
Else: Me.Requirement.BackColor = Beige 'both of the values are missing
End If
End Sub
OK got the code running but not returning the correct colors yet; will continue working on it
Private Sub Form_Current()
Dim c2 As Integer
Dim c3 As Integer
c2 = IIf(IsNull(Me.Requirement)
c3 = IIf(IsNull(Me.Requirement)
'c2 = DSum("1", "Requirements", "RxTypeID = 2")
'c3 = DSum("1", "Requirements", "RxTypeID = 3")
If (c2 > 0 And c3 > 0) Then
Me.Requirement.BackColor = White 'both values present
ElseIf (c2 > 0 Or c3 > 0) Then
Me.Requirement.BackColor = White 'one value present
Else: Me.Requirement.BackColor = Beige 'no values present
End If
End Sub
Actually, above did not work, was still getting null errors under some conditions. Have reworked it and now seems to be working for all value combinations. Except cell is not changing color. Have checked the code and c2 is being fed a 1 or 0 under the right conditions. But when it gets a 1, cell color does not change to beige. Any ideas.
Thanks
Private Sub Form_Current()
Dim c2 As Integer
c2 = IIf(IsNull(Me.Requirement)
If (c2 > 0) Then
Me.Requirement.BackColor = Beige
Else: Me.Requirement.BackColor = White
End If
End Sub
Hi
Any feedback on this one; I can step througth the following code but when c2 holds a value of 1, it does not change "requirement.backcolor" to vbBrown. vbBrown has value Empty. Have not been able to figure why it does not work.
Thanks.
Private Sub Form_Load()
Dim c2 As Integer
c2 = IIf(IsNull(Me.Requirement)
If c2 > 0 Then
Me.Requirement.BackColor = vbBrown
Else
Me.Requirement.BackColor = vbWhite
End If
End Sub
Getting closer; have changed color to Access codes and in step-thru "Me.Requirement.Backcolor"
Private Sub Form_Load()
Dim c2 As Integer
c2 = IIf(IsNull(Me.Requirement)
If c2 > 0 Then
Me.Requirement.BackColor = 14480885
Else
Me.Requirement.BackColor = 14150650
End If
End Sub
Business Accounts
Answer for Membership
by: angelIIIPosted on 2009-01-29 at 03:49:38ID: 23496157
>RxTypeID = 2 and RxTypeID = 3.
that would be:
RxTypeID = 2 or RxTypeID = 3.
a single variable cannot have 2 values at the same time?...
please clarify