I can pass a textbox to another sub or function like this below.
Code:
Private Sub txtCreditFee_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
HighlightTextBoxOnEnter Me.txtCreditFee
End Sub
Public Sub HighlightTextBoxOnEnter(txtBx As TextBox)
txtBx.SelStart = 0
txtBx.SelLength = Len(txtBx.Text)
End Sub
I have 7 listboxes for each day of the week starting with Sunday. When any listbox is clicked, i want to pass a string value to search to HighlightPerson sub. There, I will need to find out what listbox is to be searched for this string, and then select that item from the listbox and move on.
The listboxes are not multiselect.
Code:
Private Sub lstSunday_Click() 'pass name to search
HighlightPerson Me.lstSunday.Column(0, Me.lstSunday.ListIndex)
End Sub
Private Sub HighlightPerson(nameToFind As String)
Dim iDay As Integer
Dim iShift As Integer
Dim lstDay As ListBox
iDay = 0
iShift = 0
Do While iDay < 7 '7 days of week - 0=Sunday, 1=Monday, etc.
lstDay = ReturnDayList(iDay) 'assign a form control to lstDay
Do While iShift >= 0
iShift = iShift - 1 'starts at last index of list and counts down
If lstDay.Column(0, iShift) = nameToFind Then
lstDay.Selected(iShift) = True 'Highlight this index
Exit Do 'find the first instance and exit
End If
Loop
iDay = iDay + 1 'next day
Loop
End Sub
Private Function ReturnDayList(i As Integer) As ListBox 'Should return an associated listbox to lstDay based on the integer passed
Select Case i
Case 0
ReturnDayList = Me.lstSunday
Case 1
ReturnDayList = Me.lstMonday
Case 2
ReturnDayList = Me.lstTuesday
Case 3
ReturnDayList = Me.lstWednesday
Case 4
ReturnDayList = Me.lstThursday
Case 5
ReturnDayList = Me.lstFriday
Case 6
ReturnDayList = Me.lstSaturday
End Select
End Function
I have this working by not using iDay and just having 7 identical loops for each day in the HighlightPerson() sub and ignoring ReturnDayList() completely.
This could all be completely pointless but i'm curious.