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

Changing background for selected record 1

Status
Not open for further replies.

frantik

Technical User
Nov 9, 2002
93
0
0
GB
I want to change the background colour for all or some fields in a record when that record is selected.

The record is selected by checking a checkbox, when the check box is selected I would like the appropriate fields highlighted, if de-selected I would like those fields un-highlighted.

At present I am using 2 text boxes on top of eachother, one with red text the other with black and =IIf([chosen_Op]=True,[Details],"") in the control source of the top text box - the red one, Details is the bottom text box. However I am not able to click in the text box to enter text - have to tab to it - and it flickers after each new entry.

There must be a better way!! - does anyone have any ideas??

Thanks

 
Hello frantik,
Please see my posts in thread702-475361 and thread703-477277.
Good Luck, Robert
•°•°•°•°•°•°•°•°•°•°•°•°•°•°•°•°•°•°•°•°•°•°•°•°•°•°•°•°•°•°•°•°•°•°•
Professional, affordable, Access database solutions and assistance °•°•°•°•°•°•°•°•°•°•°•°•°•°•°•°•°•°•°•°•°•°•°•°•°•°•°•°•°•°•°•°•°•°•°
 
Oh, the only exception is that you want to select the color in the paint dumper icon, not the "A" text icon. Robert
•°•°•°•°•°•°•°•°•°•°•°•°•°•°•°•°•°•°•°•°•°•°•°•°•°•°•°•°•°•°•°•°•°•°•
Professional, affordable, Access database solutions and assistance °•°•°•°•°•°•°•°•°•°•°•°•°•°•°•°•°•°•°•°•°•°•°•°•°•°•°•°•°•°•°•°•°•°•°
 
Hi Frantik, maybe also take a look at a couple of my prior posts.

Access 97 thread702-458318

Access 2000+ thread181-453702
 
Hi Bill

I have had a look thanks but I can't get it to work, nothing happens at all.

I have editted the code as below:

where Fm_Risk_Ass is the main form
Fm_Q_Options is the subform
Option is the key field on the subform

I have included the code in the On current event for the sub form.

PLease can you tell me what I am doing wrong?

thanks



Private Sub Form_Current()
Dim ctl As Control, strForm As String
Dim varCondition As Variant
On Error Resume Next
varCondition = Me!Option
For Each ctl In Forms Risk_Ass.Fm_Q_Options.Form.Controls
With ctl
If Chosen_Op = True Then
With Forms!Fm_Risk_Ass.Fm_Q_Options.Form.Controls(ctl.Option).FormatConditions _
.Delete 'Delete any other Conditional Formatting, limit is 3
End With

With Forms!Fm_Risk_Ass.Fm_Q_Options.Form.Controls(ctl.Option).FormatConditions _
.Add(acExpression, , "[Option]=" & varCondition)
.BackColor = 14024661 'Light Green
.ForeColor = 0 'Black
End With
End If
End With
Next ctl

End Sub
 
Hi

Replace your code with this:

Private Sub Form_Current()
Dim ctl As Control
On Error Resume Next
For Each ctl In Forms!Fm_Risk_Ass.Fm_Q_Options.Form.Controls
With ctl
If .Tag = "ConditionalFormat" Then
With Forms!Fm_Risk_Ass.Fm_Q_Options.Form.Controls(ctl.Name).FormatConditions _
.Delete
End With

With Forms!Fm_Risk_Ass.Fm_Q_Options.Form.Controls(ctl.Name).FormatConditions _
.Add(acExpression, , "[Chosen_Op] = " & True)
.BackColor = 14024661
.ForeColor = 0
End With
End If
End With
Next ctl
End Sub


Remember to type in ConditionalFormat in the Tag property of all the controls that you want this to work on.

Good Luck
 
Thanks for the code Bill

I copied it and pasted it into the on current event for the subform - but it still does nothing.

I have set the tag property on every text box I want it to work on!

Any more ideas?

Thanks
 
Hallo,

The following FAQs in the Access Other topics Forum may be of some help.

How to highlight the selected record in a continuous form?
How do I get different coloured text for records?
How do I get different background colours for records?

- Frink

 
Hi frantik,

I've posted the DB that I did this in, at: If you download frantik.zip you will be able to see what we are doing differently.

Honestly, it does everything you asked for in your 1st posting.

Keep my fingers crossed for you.

Good Luck
 
Thanks a Mil Bill - you are so right - it does everything I want. I love it!

But you will just not believe this - when I copy your form it into my db it works great - when I point your controls to my fields it works great - when I add new controls - pointing towards my fields they don't work - How odd is that - I can see nothing different in the control properties - do you have any ideas?

Thanks
 
It's pretty odd, works ok here. Haven't any suggestions.

Can you make a copy of your DB, delete any sensitive material, just need empty table, query and Form's your doing this on, zip it up and email it to me at billpower@cwcom.net. It's going to be something really obvious I bet.

 
Hi,

How did you get on with this. Do I need to give myself a kick for missing the obvious, would be grateful if you'd let me know so that I can tell others what to look out for if I suggest something similar in the future.

Thanks

Bill
 
Hi frantik, thanks for the DB, it's looking good.

Basically the problem is that you are not Referencing the Main Form and Sub Form correctly in the following:

Forms!Fm_Risk_Ass!Fm_Q_Options.Form.Controls

In the 3 lines where the above appear in your example DB, change to:

Forms![This one main including sub]!Fm_suboptions.Form.Controls

All I've done is changed the Main Form name that holds the Sub Form (Green) and entered the Sub Form name as it appears in the Main Form's properties (Red).
Will E-mail changes.

All the best

Bill

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top