Adding a "dynamic" combo box with today's date

  • Thread starter Thread starter roadie.girl
  • Start date Start date
R

roadie.girl

I am trying to fill in the fields of my combo box.

this combo box really isn't bound to any table, but i'd like it to
contain today's date and the 5 previous days to today's date ie
DateAdd("d", -5, Date).

I can't figure out how to put this in the combo box though.

Do you guys have any suggestions?

Thanks!
Rebekah
 
Here is a function that will return a value list for your combo:
*********Start Code*************
Function MakeDateValues() As String
Dim strDateValues As String
Dim lngDateCounter As Long

strDateValues = CStr(Date)
For lngDateCounter = 1 To 5
strDateValues = strDateValues & ";" & CStr(DateAdd("d",
-lngDateCounter, Date))
Next lngDateCounter
MakeDateValues = strDateValues
End Function
********End Code*************

I would call it from the form's Load Event:

Me.MyCombobox.RowSource = MakeDateValues()

Also, be sure the Row Source Type is set to Value List.
 
I am trying to fill in the fields of my combo box.

this combo box really isn't bound to any table, but i'd like it to
contain today's date and the 5 previous days to today's date ie
DateAdd("d", -5, Date).

I can't figure out how to put this in the combo box though.


Using a table is way easier than the other possibilities.
Actuall, you can use a table that is useful in many
situations. Just create a little one field table named
Numbers with a field named Num, then populate the table with
values 1, 2, . . ., NN where NN is bigger than whatever you
need in any situation (if a new situation arises, you can
always add more records).

With that in place, your combo box's RowSource can be the
query:

SELECT DateAdd("d", 1 - Num, Date()) As f1
FROM Numbers
WHERE Num <= 6
 
I really disagree with using a table for something like this.
1. It has to be updated
2. It required a database fetch - extra time
3. The function I posted will do quite well - All done in memory and
requires no maintenance.
 
You are of course welcome to your opinion, but IMO:

1. The table does NOT need to be updated.
2. Access is pretty good at data fetches, especially for
such a small number of records.
3. Neither approach requires maintenance, but I think in
general code is less maintainable than a simple table.
4. This kind of table has many uses and I have one like this
in every app I create.
 
Back
Top