' Requery control.
Control.ColumnWidths = Control.ColumnWidths
Name
|
Value
|
---|---|
acLBInitialize
|
0
|
acLBOpen
|
1
|
acLBGetRowCount
|
3
|
acLBGetColumnCount
|
4
|
acLBGetColumnWidth
|
5
|
acLBGetValue
|
6
|
acLBGetFormat
|
7
|
acLBClose
|
8
|
acLBEnd
|
9
|
Name | Value |
---|---|
acLBOpenAsVariant | 2 |
' Control IDs.
Const DefaultId As Long = -1
Const ResetId As Long = 0
Const ActionId As Long = 1
' Setting IDs.
Const StartDateId As Long = 1
Const RowCountId As Long = 2
Const FormatId As Long = 3
Case acLBOpenAsVariant
' Id: Action.
' Row: Parameter id.
' Column: Parameter value.
Select Case Id
Case DefaultId ' Default call.
If Not Initialized Then
Start = Date
Year = VBA.Year(Start) ' Year of the first month to list.
Month = VBA.Month(Start) + 1 ' Month of the second month to list.
RowCount = Years * MonthsPerYear ' Count of rows to display.
If Control.ControlType = acComboBox Then
Format(1) = Control.Format ' Retrieve the display format from the combobox's Format property.
Control.LeftMargin = LeftMargin ' Adjust left margin of combobox.
Else
Format(1) = ListboxFormat ' Set the display format for the listbox.
End If
Initialized = True
End If
Case ResetId ' Custom call. Ignore custom settings for the current control.
Initialized = False
Case ActionId ' Custom call. Set one optional value.
' Row: The id of the parameter to adjust.
' Column: The value of the parameter.
Select Case Row
Case StartDateId ' Start date.
Start = Column
Year = VBA.Year(Start) ' Year of the first month to list.
Month = VBA.Month(Start) + 1 ' Month of the second month to list.
Case RowCountId ' Count of weeks to list.
RowCount = Column
Case FormatId ' Format for display.
If VarType(Column) = vbString Then
Format(1) = Column
End If
End Select
End Select
' Set custom parameters for a ComboBox or a ListBox having the function
' CallUltimoMonthDates as RowsourceType.
'
' Usage, where the parameter Object is a ComboBox or a ListBox object:
'
' Set start date of list:
' ConfigUltimoMonthDates Object, , #1/1/2020#
'
' Set count of dates to list (for ComboBox only, ignoreded for ListBox):
' ConfigUltimoMonthDates Object, , , 10
'
' Set all parameters:
' ConfigUltimoMonthDates Object, #4/1/2000#, 18
'
' Reset all parameters to default settings.
' NB: Could (should) be called when unloading the form:
' ConfigUltimoMonthDates Object
'
' 2021-03-01. Cactus Data ApS, CPH.
'
Public Sub ConfigUltimoMonthDates( _
ByRef Control As Control, _
Optional ByVal StartDate As Date, _
Optional ByVal RowCount As Long, _
Optional ByVal Format As String)
Const FunctionName As String = "CallUltimoMonthDates"
Const NoOpValue As Long = 0
Const DefaultId As Long = -1
Const ResetId As Long = 0
Const ActionId As Long = 1
Const StartDateId As Long = 1
Const RowCountId As Long = 2
Const FormatId As Long = 3
Dim ControlType As AcControlType
Dim SetValue As Boolean
If Not Control Is Nothing Then
ControlType = Control.ControlType
If ControlType = acListBox Or ControlType = acComboBox Then
If Control.RowSourceType = FunctionName Then
If RowCount <> NoOpValue Then
If Control.ControlType = acListBox Then
' Setting of row count not supported.
RowCount = NoOpValue
End If
End If
' Make sure, that this control has called the callback function to be initialized.
' That may not be the case, if this configuration function is called during form loading.
Application.Run FunctionName, Control, DefaultId, NoOpValue, NoOpValue, acLBOpenAsVariant
' Set parameter(s) and run the function by its name.
If DateDiff("d", StartDate, #12:00:00 AM#) <> 0 Then
Application.Run FunctionName, Control, ActionId, StartDateId, DateValue(StartDate), acLBOpenAsVariant
SetValue = True
End If
If RowCount > 0 Then
Application.Run FunctionName, Control, ActionId, RowCountId, RowCount, acLBOpenAsVariant
SetValue = True
End If
If Format <> "" Then
Application.Run FunctionName, Control, ActionId, FormatId, Format, acLBOpenAsVariant
SetValue = True
End If
If Not SetValue = True Then
' Reset to default values.
Application.Run FunctionName, Control, ResetId, NoOpValue, NoOpValue, acLBOpenAsVariant
End If
' Apply settings.
Application.Run FunctionName, Control, DefaultId, NoOpValue, NoOpValue, acLBOpenAsVariant
' Requery control.
Control.ColumnWidths = Control.ColumnWidths
End If
End If
End If
End Sub
Private Sub UltimoSelect_AfterUpdate()
Dim StartDate As Date
Dim RowCount As Long
Dim Enabled As Boolean
Select Case UltimoSelect.Value
Case 0
' List dates from today.
StartDate = Date
' Allow to adjust the count of months to list.
RowCount = Me!DateRows.Value
Enabled = True
Case 1
' List the current year's ultimo month dates.
StartDate = DateSerial(Year(Date), 1, 1)
' Lock row count to the count of months for a year.
RowCount = MonthsPerYear
Enabled = False
End Select
Me!DateRows.Value = RowCount
Me!DateRows.Enabled = Enabled
Me!DateRows.Locked = Not Enabled
ConfigUltimoMonthDates Me!UltimoMonthDates, StartDate, RowCount
End Sub
Have a question about something in this article? You can receive help directly from the article author. Sign up for a free trial to get started.
Comments (0)