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

Background color of current record? 1

Status
Not open for further replies.

gtroiano

Technical User
Nov 7, 2001
99
US
i have a continuous sub form with three fields per record based on a table and i would like to have the background color of the entire record change of the when it's is selected. i set the background color of each of the controls to the highlight color and then set the back style to transparent but that will only "highlight" the active control. i also tried the example from and it works but on the main form that the sub form is on i have a text box and a "Find Next" button used to search the table. for reasons that are beyond my knowledge, when i use the example from the afformentioned link the search function only goes to the first matching record and then the "Find Next" button doesn't return any more matching records. if someone has an alternative way of hightlighting the whole record, i would appreciate it greatly.

this is the code behind the search text box:
[red]Private Sub txtFind_AfterUpdate()
On Error GoTo Err_txtFind_AfterUpdate

Dim stResponse As String

stResponse = txtFind
If stResponse = "" Then
GoTo Exit_txtFind_AfterUpdate
Else

If Me.optSearch = 1 Then stFindCriteria = "[AccountTitle] Like '*" Else
If Me.optSearch = 2 Then stFindCriteria = "[AccountNumber] Like '*" Else
If Me.optSearch = 3 Then stFindCriteria = "[FamsNumber] Like '*" Else
stFindCriteria = stFindCriteria & stResponse & "*'"
End If

Me.fsubMaintainAccounts.Form.RecordsetClone.FindFirst stFindCriteria
If Me.fsubMaintainAccounts.Form.RecordsetClone.NoMatch Then
MsgBox "Search text was not found."
stFindCriteria = ""
Else
Me.fsubMaintainAccounts.SetFocus
Me.fsubMaintainAccounts.Form.Bookmark = Me.fsubMaintainAccounts.Form.RecordsetClone.Bookmark
End If

Exit_txtFind_AfterUpdate:
Exit Sub

Err_txtFind_AfterUpdate:
Resume Exit_txtFind_AfterUpdate
End Sub[/color]

this is the code behind the "Find Next" button:
[red]Private Sub cmdFindNext_Click()
On Error GoTo Err_cmdFindNext_Click

If stFindCriteria = "" Then
GoTo Exit_cmdFindNext_Click
Else
Me.fsubMaintainAccounts.Form.RecordsetClone.FindNext stFindCriteria
If Me.fsubMaintainAccounts.Form.RecordsetClone.NoMatch Then
MsgBox "Search text was not found."
stFindCriteria = ""
Else
Me.fsubMaintainAccounts.SetFocus
Me.fsubMaintainAccounts.Form.Bookmark = Me.fsubMaintainAccounts.Form.RecordsetClone.Bookmark
End If
End If

Exit_cmdFindNext_Click:
Exit Sub
Err_cmdFindNext_Click:
Resume Exit_cmdFindNext_Click
End Sub[/color]

i can post the code for the highlighting example from if it helps but if you are familiar with it, all the better. thanks.
 
Hallo,

These two FAQs may give you some ideas:

How do I get different background colours for records
and
How do I get different coloured text for records

- Frink
 
thanks for the help but i am trying to make the whole record(row) highlighted when it's selected. like i said, i can have it working but somehow the highlighting screws up the search function i have. any other suggestions?

jerry.
 
Hallo,

Based on the FAQ, why not make the coloured box fill the whole row, rather than just a control?
You'd have to put some code to adjust the formatting based on the current record number, rather than a value in the record, but that shouldn't be too tricky if you've a decent Primary Key.

- Frink
 
i imagine that would work; perhaps the title of the thread was deceiving. i do not just want the background of the controls to change color. it should be as if you were to take a highlighter and make a solid line over a sentence. if that makes sense? as i said, the example from works but it interfers with the code i pasted above for the search function. if what your explaining can do this andi am just thick in the skull an example of some code would be appreciated. thanks.

jerry.
 
Hallo,

I'll try to explain, but it will take a bit of coding understanding to get it to work.

Firstly I'll assume your form is based on a table with a (long) primary key of lngId.

Create a text field control txtBackground to the size of your whole record, and send it to the back of the form.
Make the font WebDings and the forecolor the 'selected' colour you want. Make the background colour the 'unselected' colour.

Make the background colour of all your controls in the record as the selected colour, but make them all transparent.

Create a new text control called txtCurrentRecord and put it in the form header or footer. You can make this invisible once you've checked that it works.
In the OnCurrent Event procedure, put:
Me!txtCurrentRecord = Me!lngId

Set the Control Source of txtBackground:
=IIf([lngId]=[txtCurrentRecord],String$(3,"g"),"")

This field will be empty unless the record you're on is the current record, in which case it would be a string of 3 WebDings g characters, which happen to be a solid block.

If the coloured bar is not tall enough then increase the font size in txtBackground.
If the coloured bar is too narrow then increase the '3' in the Control Source.

Hope that makes your forms prettier,

- Frink
 
Frink,

thanks. it workerd perfectly. you're a lifesaver.

jerry.
 
Super, FYI I've put it in a FAQ titled:
How to highlight the selected record in a continuous form

- Frink

P.S. Thanks for the
star.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top