Highlight row (1 Viewer)

oxicottin

Newbie
Joined
Jun 26, 2007
Messages
495
Hello, I have a control txt1 that I what to highlight yellow if the text says "Lunch" or "Scheduled Break" and I also want to highlight the textboxes in the same row OR is there an easy way I can highlight a background texbox that would shw yellow and cover the record? I need it to do what it would do like conditional format would in excel... How could it be done?

Thanks!
 

CJ_London

Super Moderator
Staff member
Joined
Feb 19, 2013
Messages
11,562
use conditional formatting - very similar to excel. In form design view, click on a textbox and then the format tab in the ribbon.

You can use a background textbox if you want - just make sure you move it to back
 

oxicottin

Newbie
Joined
Jun 26, 2007
Messages
495
the tut helped out thank you but what sintax would I use if I was looking for a word? I tried just entering "Lunch" or "Scheduled Break". and got no results.
 

Galaxiom

Super Moderator
Staff member
Joined
Jan 20, 2009
Messages
11,819
BTW Recording repeating information as long strings and searching for it is not best practice. Far better to use a number with a lookup to display the words. It is more compact to store, far more efficient to process and light years ahead if the display names need to be changed or more terms added.

In your case "Lunch" and "Scheduled Break" would be represented by a numeric IDs that lie within a specified range. The Conditional Formatting would test for the ID being in that range.

So when you need to change the displayed words or add "Afternoon Tea" to the same group you don't have to change the code. You simply add another record to a the lookup table with an ID in the same range.

If you need to change code when you fiddle with the data then you should reconsider your approach. A well structured database can be extended by just adding records.
 

oxicottin

Newbie
Joined
Jun 26, 2007
Messages
495
Galaxiom thats a great thought! I switched it up a bit and am trying it from vba ut I cant get it to work its just making all my text in my column red insted of the ones I need.

Code:
Private Sub Form_Current()
If Me.txtAlrmCodeId = "2101" Or "2102" Or "2103" Or "2104" Or "2105" Or "2106" Or "2107" Or "2108" Then
   Me.txtDelayReason.ForeColor = vbRed
   Me.txtDelayReason.BackColor = RGB(236, 236, 236) 'Or VB Color 15527148
   Me.txtDelayReason.FontBold = True
Else
   Me.txtDelayReason.ForeColor = vbBlack
   Me.txtDelayReason.BackColor = RGB(236, 236, 236) 'Or VB Color 15527148
   Me.txtDelayReason.FontBold = False
End If
End Sub
 

CJ_London

Super Moderator
Staff member
Joined
Feb 19, 2013
Messages
11,562
long winded by but this

If Me.txtAlrmCodeId = "2101" Or "2102" Or "2103" Or "2104" Or "2105" Or "2106" Or "2107" Or "2108" Then

should be

If Me.txtAlrmCodeId = "2101" Or Me.txtAlrmCodeId = "2102" Or Me.txtAlrmCodeId = "2103" .... Then

alternatively

If Me.txtAlrmCodeId IN ("2101","2102","2103" ...) Then

but if txtAlrmCodeI is numeric, you don't need the quote marks which indicate text
 
Last edited:

Galaxiom

Super Moderator
Staff member
Joined
Jan 20, 2009
Messages
11,819
Galaxiom thats a great thought! I switched it up a bit and am trying it from vba ut I cant get it to work its just making all my text in my column red insted of the ones I need.
Won't work in VBA for two reasons. You need to use ConditionalFormatting because in VBA, all displayed controls are instances of the same control and all will be affected by the value in the current record.

Secondly, Me.txtAlrmCodeId = "2101" Or "2102" Or "2103"
will be always be True because "2102" is True etc.

In ConditionalFormatting you can do it like this:
Code:
AlrmCodeId IN("2101", "2102", "2103", "2104", "2105", "2106")
But then if you use actual numbers you can reliably use numeric comparisons or BETWEEN. They work for strings too but as alphanumerics the result can sometimes be unexpected.
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Top Bottom