Ark68
Well-known Member
- Joined
- Mar 23, 2004
- Messages
- 4,632
- Office Version
- 365
- 2016
- Platform
- Windows
I have this code triggered when a user selects an item form a listbox (lbx_collections). Once clicked, code is used to define values to populate other controls on the userform by cross referencing same data on a worksheet (ws_dump).
The lines purple extract a time duration (elapsed time) from column E formatted as hh:mm:ss AM/PM (which may not be the best way to display elapsed time). So cell E2 for example has a value of 12:06:33 AM, but displays as 0:06:33 to represent a duration of 6 minutes and 33 seconds.
The code captures the data correctly, however, the value is not displaying in the userform control correctly.
The duration gets populated into userform textbox "tbx_dur" from data extracted from cell (see above), with tseldur = 12:06:33 AM as 12:06:33 AM. I want this textbox to display the value as 0:06:33 (h:mm:ss). What must I do to make this happen?
Rich (BB code):
Private Sub lbx_collections_Click()
Stop
Dim tsel As String 'selected value
Dim tselix As Long 'selected index
Dim j As Long, drow As Long
Dim tseltitle As String, tserlcoll As String, tseldate As Date, tseldur As Date
Dim gt As Boolean
Dim txttseldate as string
If Not mbevents Then Exit Sub
tsel = lbx_collections.Value
tselix = lbx_collections.ListIndex
'MsgBox tsel & " (" & tselix & ")"
tseltitle = tsel '
tselcoll = lbx_collections.List(tselix, 1) 'collected?
drow = WorksheetFunction.Match(tseltitle, ws_dump.Columns("C"), 0)
'date
tseldate = ws_dump.Range("D" & drow)
tseldy = Day(tseldate)
tselmn = MonthName(Month(tseldate), True)
tselyr = Year(tseldate)
txttseldate = tseldy & "-" & tselmn & "-" & tselyr
tseldur = ws_dump.Range("E" & drow)
tselres = ws_dump.Range("F" & drow)
If ws_dump.Range("B" & drow) <> "" Then
gt = True
'get list of participants, create a list, and update lbx_smodels
With ws_dump
ml_lstrow = .Cells(.Rows.count, "AA").End(xlUp).Row
.Range("AA3:AA" & ml_lstrow).Sort key1:=.Range("L2"), Order1:=xlAscending, Header:=xlNo
.Range("AA3:AA" & ml_lstrow).Name = "modlist2"
End With
End If
mbevents = False
Me.tbx_title.Value = tseltitle
If tselcoll = "OK" Then
Me.chkbx_collected.Value = True
Else
Me.chkbx_collected.Value = False
End If
Me.tbx_date.Value = txtseldate
Me.tbx_dur.Value = tseldur
Me.cbx_res.Value = tselres
If gt = True Then
Me.chkbx_group.Value = True
Me.lbx_smodel.List = Application.WorksheetFunction.Transpose(ThisWorkbook.names("modlist2").RefersToRange)
Else
Me.chkbx_group.Value = False
Me.lbx_smodel.List = Application.WorksheetFunction.Transpose(ThisWorkbook.names("modlist").RefersToRange)
End If
mbevents = True
End Sub
The lines purple extract a time duration (elapsed time) from column E formatted as hh:mm:ss AM/PM (which may not be the best way to display elapsed time). So cell E2 for example has a value of 12:06:33 AM, but displays as 0:06:33 to represent a duration of 6 minutes and 33 seconds.
The code captures the data correctly, however, the value is not displaying in the userform control correctly.
The duration gets populated into userform textbox "tbx_dur" from data extracted from cell (see above), with tseldur = 12:06:33 AM as 12:06:33 AM. I want this textbox to display the value as 0:06:33 (h:mm:ss). What must I do to make this happen?