Gustav Brock
gustav at cactus.dk
Mon Aug 16 06:22:37 CDT 2004
Hi Arthur
> I'm having a senior moment. Given a form containing three controls:
> txtDateFrom - starting date
> txtDateTo - ending date
> lstDates - to contain one row for all dates between from and to
> inclusive
> I want to manufacture all dates between the start and end date and
> populate the listbox with same. I forget how to do it. I'm used to
> grabbing data using SQL etc. and I suppose I could just build a table
> containing loads of dates and query that, but I'm wondering how to
> manufacture the listbox rows instead.
> Will someone kindly nudge me in the right direction?
That's typically what i listbox callback function is for; no tables,
no nothing, just a simple function:
<code>
Private Function ListDaysInInterval( _
ctl As Control, _
lngID As Long, _
lngRow As Long, _
lngCol As Long, _
intCode As Integer) As Variant
Static datDateFirst As Date
Static strFormat As String
Static lngDates As Long
Dim varDateFirst As Variant
Dim varDateLast As Variant
Dim varReturn As Variant
Select Case intCode
Case acLBInitialize
strFormat = Me!txtDateFrom.Format
varDateFirst = Me!txtDateFrom.Value
varDateLast = Me!txtDateTo.Value
' Only initialize if two dates are present.
varReturn = IsDate(varDateFirst) And IsDate(varDateLast)
If varReturn = True Then
datDateFirst = CDate(varDateFirst)
lngDates = DateDiff("d", datDateFirst, CDate(varDateLast)) + 1
Else
lngDates = 0
End If
Case acLBOpen
varReturn = Timer ' Autogenerated unique ID.
Case acLBGetRowCount ' Get rows.
varReturn = lngDates ' Set number of rows.
Case acLBGetColumnCount ' Get columns.
varReturn = 1 ' Set number of columns.
Case acLBGetColumnWidth ' Get column width.
varReturn = -1 ' Use default width.
Case acLBGetValue ' Get the data.
' Calculate dates.
varReturn = DateAdd("d", lngRow, datDateFirst)
Case acLBGetFormat ' Format the data.
varReturn = strFormat ' Use format of first control.
Case acLBEnd
' Do something when form with listbox closes or
' listbox is requeried.
End Select
ListDaysInInterval = varReturn
End Function
</code>
/gustav