I need a listbox populated with the calandar days of the month, an example would be for December have the selections of 12/01/2014, 12/02/2014, etc.
Is this possible?
Thanks in adance for your assistance!!
I need a listbox populated with the calandar days of the month, an example would be for December have the selections of 12/01/2014, 12/02/2014, etc.
Is this possible?
Thanks in adance for your assistance!!
The listbox RowSource can be built with code.
How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.
Can you get me started on the code?
As an example, we're in December, so I need 12/25/2014, 12/26/2014, 12/27/2014, etc.
In January I need 01/19/2015, 01/20/2015, 01/21/2015, etc.
Thanks!!
The combobox RowSourceType property must be set to ValueList.
Private Sub List101_GotFocus()
Dim i As Integer
For i = 1 To 31
Me.List101.AddItem "Jan " & i & " 2014"
Next
End Sub
Making the upper limit of the For loop and the month and year all dynamic is the tricky part. Start with this static example. When that works, figure out how to make it dynamic (user input or current date).
How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.
Thanks!! I couldn't come up with the code.
Happy Holidays!!
Here's some code I wrote for someone a while ago that takes care of the tricky part:
As June7 said, go to Properties - Data, for the Listbox, and set the RowSource Type to Value List, then use this code, replacing lstDates, in the code, with the actual name of your Listbox:
Code:Private Sub Form_Load() Dim Days As Integer Dim DayCount As Integer Dim StartDate As Date Dim EndDate As Date StartDate = CDate(DateSerial(Year(Date), Month(Date), 1)) EndDate = CDate(DateSerial(Year(Date), Month(Date) + 1, 0)) Me.lstDates.RowSource = "" DayCount = DateDiff("d", StartDate, EndDate) For Days = 0 To DayCount Me.lstDates.AddItem Format(DateAdd("d", Days, StartDate), "mm/dd/yyyy") Next Days End Sub
I have to say I'd use a Combobox for this, instead of a Listbox, simply because of the space involved, but the code for either, in this case, would be the same. When using the Combobox, I'd probably use the GotFocus event, as June7 did, but an empty Listbox, when the Form loads, looks sort of dorky, which is why I used the Form_Load event; the code will work in either.
Linq ;0)>
Private Sub List101_GotFocus()
Dim i As Integer
For i = 1 To 31
Me.List101.AddItem Year(Date) & "/" & Month(Date) & "/" & i
Next
End Sub
Not every month has 31 days. Linq's code deals with that.
How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.