1

I have an MS Access continuous form on onload event i am getting MyTable Record, upto here its fine. But i want to change the color of only first row

MyTable

Id ¦ Name ¦  Months ¦ Years
------------------
1  ¦ Ali  ¦ 01 ¦ 2020
2  ¦ Umar ¦ 02 ¦ 2020
3  ¦ Abid ¦ 03 ¦ 2019
4  ¦ Sana ¦ 04 ¦ 2020

I used this code

Dim tblCount, Countr as Integer
tblCount = Dcount("Years", "MyTable")
For Countr = 1 to tbleCount
 If countr = 1 Then
   Me.Years.ForeColor = vbred
 Else
   Me.Years.ForeColor = vbblack
End If
Next Countr

When countr = 1 it shows all Years Column Red and when Countr > 1 Years Column becomes black But i want only first row Years Red rest all rows Black

I really thankful to you plzz help me

  • Normally, programmatically changing property of control on form affects ALL instances of control. Use Conditional Formatting, not VBA. CF applies to only textbox and combobox. – June7 May 10 '20 at 19:22
  • Review https://www.accessforums.net/showthread.php?t=80081 for possible solution. – June7 May 10 '20 at 19:28
  • Really appreciated for a quick reply. How can i use CF to get Minimum Month and Years value ( in my case which is March 2019) and change its color to red? – Usman Saeed May 10 '20 at 19:54
  • If records are sorted so lowest record ID is always the first record, have a textbox with expression `=Min([ID])` and CF rule `=[tbxMin]`. This will fail if user change sort order. – June7 May 10 '20 at 21:23
  • Highlighting first record regardless of record order would require calculating a row number. Calculating a row number on form is difficult and topic of many discussions. Without this calculated value, I don't see any way to accomplish what you want with CF or VBA. This would be simple on a report where textbox has RunningSum property. – June7 May 10 '20 at 21:28
  • How can i achieve this on report? I have managed to get lowest year and month ``` 3 ¦ Abid¦03¦2019 ``` on report but now how to apply CF? I am sorry if i am silly to ask question like this actually im new to programming. – Usman Saeed May 10 '20 at 22:32
  • Have textbox tbxRowNum with ControlSource `=1` and RunningSum property set to OverAll. CF expression rule `[tbxRowNum] = 1`. – June7 May 10 '20 at 22:51

0 Answers0