Results 1 to 3 of 3
  1. #1
    vicsaccess's Avatar
    vicsaccess is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Apr 2015
    Posts
    451

    combo box with dynamic dates?


    ok, here's one I hadn't heard of but thought it would be better on my form to pick dates rather than a date picker that needs more code to check that the user hasn't picked dates in the past or too far in the future etc. can a combo box be populated with dates based off of todays date? ideally it would hold 14 or so dates starting with today and the next 14 dates. tomorrow it would adjust to tomorrows date with 14 more dates in the future. was thinking about this today, did a little research but didn't find anything close so I thought for fun I would see if anyone has ever done something like this.

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    VBA code can build the combobox RowSource.

    From MSKB:

    "In Visual Basic, set the RowSourceType property by using a string expression with one of these values: "Table/Query", "Value List", or "Field List". You also use a string expression to set the value of the RowSource property. To set the RowSourceType property to a user-defined function, enter the name of the function."

    Code to build the list could be like:

    Me.cbxName.AddItem Date()
    For x = 1 to 14
    Me.cbxName.AddItem Date() + x
    Next
    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.

  3. #3
    vicsaccess's Avatar
    vicsaccess is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Apr 2015
    Posts
    451
    thanks June7, that looks simpler. I did find a close proximity to what I was thinking over at bytes.com and adjusted it to work. i'll have to try yours, it looks like less of a hastle
    Code:
    Private Sub Form_Load()
        Me.cbodate.RowSourceType = "value list"
        m1 = Format(DateAdd("d", 1, Date), "mm/dd/yyyy")
        m2 = Format(DateAdd("d", 2, Date), "mm/dd/yyyy")
        m3 = Format(DateAdd("d", 3, Date), "mm/dd/yyyy")
        m4 = Format(DateAdd("d", 4, Date), "mm/dd/yyyy")
        m5 = Format(DateAdd("d", 5, Date), "mm/dd/yyyy")
        m6 = Format(DateAdd("d", 6, Date), "mm/dd/yyyy")
        m7 = Format(DateAdd("d", 7, Date), "mm/dd/yyyy")
        m8 = Format(DateAdd("d", 8, Date), "mm/dd/yyyy")
        m9 = Format(DateAdd("d", 9, Date), "mm/dd/yyyy")
        m10 = Format(DateAdd("d", 10, Date), "mm/dd/yyyy")
        m11 = Format(DateAdd("d", 11, Date), "mm/dd/yyyy")
        m12 = Format(DateAdd("d", 12, Date), "mm/dd/yyyy")
        m13 = Format(DateAdd("d", 13, Date), "mm/dd/yyyy")
        m14 = Format(DateAdd("d", 14, Date), "mm/dd/yyyy")
        
        Me.cbodate.RowSource = m1 & ";" & m2 & ";" & m3 & ";" & m4 & ";" & m5 & ";" & m6 & ";" & m7 & ";" _
        & m8 & ";" & m9 & ";" & m10 & ";" & m11 & ";" & m12 & ";" & m13 & ";" & m14
        
        
    End Sub

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Dynamic Dates in Crosstab Column Headings
    By air3jxt in forum Queries
    Replies: 5
    Last Post: 03-05-2014, 05:57 PM
  2. dynamic combo boxes
    By brad in forum Forms
    Replies: 1
    Last Post: 04-15-2013, 01:07 PM
  3. Dynamic combo box
    By Accessuser67 in forum Forms
    Replies: 6
    Last Post: 01-10-2013, 03:23 PM
  4. Dynamic dates with query
    By unslog in forum Access
    Replies: 2
    Last Post: 03-23-2012, 07:27 AM
  5. Dynamic Cascading Combo Box
    By Userdd in forum Forms
    Replies: 5
    Last Post: 07-24-2011, 07:37 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums