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

How to highlight a row on a datasheet in code

Status
Not open for further replies.

projecttoday

Programmer
Feb 28, 2004
208
US
I have a datasheet subform on a form. I am able to move the arrow to a row on the datasheet using recordsetclone.findfirst. What I would like to do is actually highlight the whole row as if it had been clicked on. As I said I'm finding the row okay with findfirst. How do I highlight it? Would that be setfocus? What code would I use after

me.subformname.recordsetclone.findfirst

?

Robert
 
You will need conditional formatting.
See thread702-1377558. Read Ace Man's solution. You will have to apply conditional formatting to each textbox.
 
oops. that is for alternating rows. The idea is the same for selecting a row. Wait one I will send it.
 
Sorry for not getting back. Here is the code in the form's module.

Code:
Private Sub Form_Current()
 Me.Recalc
End Sub

Public Function HiliteRow() As Boolean
   Const PKname = "importID"
   Me.RecordsetClone.FindFirst "[" & PKname & "] =" & Me(PKname)
   If (Me.RecordsetClone.AbsolutePosition) = Me.Recordset.AbsolutePosition Then
      HiliteRow = True
   End If
End Function
put in your PKName

in conditional formatting
hiliteRow() = true
 
I get "Compile Error Variable not defined" on "HiliteRow = True
 
My guess, you probably made it a sub routine not a function. Post your code.
 
I don't get it. Why do I need a function? Where is the function called?
 
Where is the function called
In the conditional formatting expression:
HiliteRow() = True

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
You need to read the original thread. You have to use conditional formatting on a continous form. In a continous form there are only one set of controls, all other rows are just projections of the one set of controls. So if you would change the properties of a control through code, Every representation (row) will also change. Conditional formatting is the only way to display different properties per row.
 
I find that the easiest way to do this is using the method proposed by RoyVidar ( and that is to put a control in the form header (txtHighlight, say) which is updated to the key field in the current event:

Code:
Private Sub Form_Current()
    Me.txtHighlight = Me.FormKeyFieldName
End Sub

And to set Conditional Formatting to:

Code:
Expression Is: [FormKeyFieldName]=[txtHighlight]

 
Yeah that would be way more efficient. Now you just compare each record against a value instead of performing a recordset search for reach record.
 
Well, I have a strange problem. Format / Conditional formatting is grayed out on both the datasheet and the main form. Any ideas why?
 
Can only be used on Text boxes. No checkboxes or combos.
 
If you need other controls, build a continous form and put a single textbox behind all the other controls. Make it locked and disabled. Set the conditional to that text box.
 
How do you put a textbox behind another control? You mean physically behind? My datasheet must be enterable.
 
Thanks for posting. I really need to keep it in datasheet view. Does anybody have any ideas?
 
Why do you need to keep it in datasheet view? You lose a lot of functionality. It is possible to create a continuous form that looks very like a datasheet.

 
Your choices are

1) Use a datasheet and have all the controls be textboxes, or at least use conditional formatting on the controls that are textboxes
2) Use a continous form to look like a datahseet, as already demonstrated
3) Go to the windows API forum and spend a few weeks and few hundred lines of code to see if you can do this. There are some examples on lebans.com of api calls to do conditional formatting unfortunately the dibsection rendering does not work in a datasheet.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top