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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Code on Continuous Form to perform action on unique record 2

Status
Not open for further replies.

cstuart79

Technical User
Nov 2, 2009
171
US
So I have the following code added to a check box on a continuous form. The code is successful in changing the color of the field upon clicking the checkbox; however, all records change colors when 1 single checkbox is clicked. Please help me revise the code to make it so each checkbox for each entry is unique!

Private Sub Check32_Click()
If Me.Check32.Value = True Then
Me.Sender_Comp_ID.BackColor = RGB(0, 255, 0)
Me.Port.BackColor = RGB(0, 255, 0)
Else
Me.Sender_Comp_ID.BackColor = RGB(255, 255, 255)
Me.Port.BackColor = RGB(255, 255, 255)
End If
End Sub
 
cstuart79,
"check32"? Do yourself a favor and kick your development up a notch and name your significant controls. Go back and look at the code that I have provided in other answers to your questions. Notice there are no "Command34" or "Text5" or "Check32". Please update your control names so we get the feeling you are learning something from our help.

Regarding your question, you can't change a single instance of a control in a continuous form without using something like Conditional Formatting. If a check box isn't bound to a field in your form's record source, it can't be differentiated from every other instance of the check box in the form.

Duane
Hook'D on Access
MS Access MVP
 
Got it Duane. I appreciate your teaching me! It is bound to a field "Primary_Session" in my form's record source "SESSIONS", so should it read something like this in the "after update" event of "chkPrimary_Session"?

Private Sub chkPrimary_Session_AfterUpdate()
If Me.Parent.SESSIONS.Primary_Session.Value = True Then
Me.Sender_Comp_ID.BackColor = RGB(0, 255, 0)
Me.Port.BackColor = RGB(0, 255, 0)
Else
Me.Sender_Comp_ID.BackColor = RGB(255, 255, 255)
Me.Port.BackColor = RGB(255, 255, 255)
End If
End Sub
 
I tried the following but was unsuccessful:

Dim objFrc As FormatCondition
Dim lngGreen As Long
lngGreen = RGB(0, 255, 0)

Me.Sender_Comp_ID.FormatConditions.Delete
Set objFrc = Me.Sender_Comp_ID.FormatConditions.Add(Primary_Session.Value = True)

With Me.Sender_Comp_ID.FormatConditions
.Add.BackColor = RGB(0, 255, 0)
End With

End Sub


This worked for except it applied to all in the continuous form. Maybe I simply add the "FormatConditions.Delete" clause?

Private Sub Check32_Click()
If Me.Check32.Value = True Then
Me.Sender_Comp_ID.BackColor = RGB(0, 255, 0)
Me.Port.BackColor = RGB(0, 255, 0)
Else
Me.Sender_Comp_ID.BackColor = RGB(255, 255, 255)
Me.Port.BackColor = RGB(255, 255, 255)
End If
End Sub

Or add the clause to this that references parent form?

Private Sub Check32_AfterUpdate()
If Me.Parent.SESSIONS.Primary_Session.Value = True Then
Me.Sender_Comp_ID.BackColor = RGB(0, 255, 0)
Me.Port.BackColor = RGB(0, 255, 0)
Else
Me.Sender_Comp_ID.BackColor = RGB(255, 255, 255)
Me.Port.BackColor = RGB(255, 255, 255)
End If
End Sub
 
Why do you think you need to use code? Can't you just set up your conditional formatting in design view? Isn't your request based on a standard business rule or requirement?

Can't you just select first the Sender_Comp_ID control and set the conditional formatting and then do the same for the Port control?

Duane
Hook'D on Access
MS Access MVP
 
it doesn't allow me to do conditional formatting on a check box in design view. i tried to use the design view on Sender_Comp_ID to create an expression that references the check box but it does not yield any results:

Sender_Comp_ID Text Box
Condition 1:
Expression Is SESSIONS.chkPrimary_Session.Value=True

the problem is that i want the Sender_Comp_ID text box to change color based upon the state of a check box.
 
I doubt the name of your check box on your form is "SESSIONS.chkPrimary_Session.Value".
What happens if you try:
[tt]
Sender_Comp_ID Text Box
Condition 1:
Expression Is chkPrimary_Session=True
[/tt]


Duane
Hook'D on Access
MS Access MVP
 
tried your suggestion but still no action takes place, no errors but no changes to the field.
 
Is the background of the text box set to something other than transparent? Did you try mess with other properties? Did you try create this on the simplest of forms with the simplest of field values and the simplest of expressions?

Isn't this basic conditional formatting? How is your situation different from every other situation where this works?

Duane
Hook'D on Access
MS Access MVP
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top