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

highlight a value from a list box on a form

Status
Not open for further replies.

crisis2007

Technical User
Apr 2, 2007
114
US
I have no idea if this is even possible:

I have a listbox on a form. This listbox is populated with dates in the first column and shift numbers in the second such as below:

12/01/2012 1A
12/01/2012 1B
12/01/2012 1C
12/02/2012 1A
12/02/2012 1B
12/02/2012 1C
12/03/2012 1A
12/03/2012 1B
12/03/2012 1C
etc.
Is there a way that when the form opens, it highlights one of the values that reflects today's date? I appreciate any help on this!!!
 
There are at least three values that reflect today's date. Which one do you want to select? You should be able to set the value of the listbox in the Open event of the form. This depends on the bound column of the listbox.

Code:
Me.lboDateShift = Date


Duane
Hook'D on Access
MS Access MVP
 
That is what I tried. Here is the code I use:

Private Sub Form_Open(Cancel As Integer)
Me.List0.Requery
Me.List0 = Date
End Sub

The requery is necessary as new data fills the listbox when a new schedule is created. I am not sure if it is because of the requery or if it is due to the duplicated dates that is won't highlight. I am wondering if it just does not know which of the duplicated dates to highlight.
 
And I should have clarified, there will always be at least three values with the same dates. They will have different shift numbers on each of those same dates.
 
I can't see any reason for a requery when a form opens.

IMO, the bound column of every listbox and combobox should be unique for every item in the list. If not, your design is wrong.

Duane
Hook'D on Access
MS Access MVP
 
Thanks for your help. It's a little complicated to explain but the column showing the dates is not the bound column. There is a unique ID column that is hidden in the listbox. I imagine that is why this is not working.
 
Furthermore, I'd use the Load event instead of Opeh

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
I agree with PH.

crisis2007,
We can't help unless you give us enough information to help. Consider providing some information about your listbox like:
Bound Column
Column Count
Column Widths
Row Source

Duane
Hook'D on Access
MS Access MVP
 
Ok I will give it a shot here -


The Column Fields are:
C_ActivityID (Bound Column)
C_ActivityDate
C_ActivityPrecinct
C_ActivityTeam

So 4 Columns
Column widths: 0";0.9403";0";0.2"

Row Source: SELECT T_C.C_ActivityID, T_C.C_ActivityDate, T_C.C_ActivityPrecinct, T_C.C_ActivityTeam FROM T_C WHERE (((T_C.C_ActivityDate) Is Not Null) AND ((T_C.C_ActivityPrecinct)="N") AND ((T_C.C_ActivityTeam) Is Not Null)) ORDER BY T_C.C_ActivityDate DESC , T_C.C_ActivityTeam DESC;
 
Code:
 Dim i As Integer
  Dim strDate As String
  strDate = Format(Date, "MM/DD/YYYY")
  For i = 0 To Me.lstDate.ListCount
    If Format(CDate(Me.lstDate.Column(1, i)), "MM/DD/YYYY") = strDate Then Exit For
  Next i
  Me.lstDate.Selected(i) = True
 
Thanks for lending your assistance MajP. I should have explained even further that there is an AfterUpdate event on the listbox that open a form pertaining to the date selected. So when I use the code you provided it opens the form and locks up. I just want the row in the list highlighted if it is possible.
 
Looks like i might just change my method and place a filter on the list box to achieve what I want to do. The whole idea was to identify the dates closest to today easily from a long list of dates.
 
crisis2007,
No offense but I hope you go back through this thread and try to learn from it. Asking a good question involves providing the right amount of accurate information about your situation and needs.

Duane
Hook'D on Access
MS Access MVP
 
when things get too complicated, I tend to like subforms, and then you can do conditional formatting of rows too, which is really easy.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top