Results 1 to 4 of 4
  1. #1
    Star Lounger
    Join Date
    Jan 2001
    Location
    Littleton, Colorado, USA
    Posts
    73
    Thanks
    0
    Thanked 0 Times in 0 Posts

    List Values for Combo Boxes (A2K, SR1)

    I am certain this is quite simple, but I have a combo box on a form to help filter the form, in part by year. I'd like this combo box to contain last year, this year, and next year. I know I could make the Row Source property to Value List and manually add the years, but then I'd need to change this list every year. What I've done to this point is make the Row Source a Query, with the following:
    <hr>SELECT Max(Year(Date())-1) AS CY FROM tblBlueCardInitiate UNION SELECT Max(Year(Date())) AS CY FROM tblBlueCardInitiate UNION SELECT Max(Year(Date())+1) AS CY FROM tblBlueCardInitiate;<hr>
    This solution works just fine, as long as there are records in tblBlueCardInitiate. If there are no records (as there wouldn't be if I distributed this database to other offices), the list is empty. I don't mind using code, but I'm sure I'm missing the simpler solution. Any thoughts?

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 28 Times in 28 Posts

    Re: List Values for Combo Boxes (A2K, SR1)

    Set the Row Source Type to Value List, leave the Row Source blank, and set the Row Source in the On Load event of the form:

    Private Sub Form_Load()
    Me.NameOfComboBox.RowSource = Year(Date) - 1 & ";" & Year(Date) & ";" & Year(Date) + 1
    End Sub

    with the appropriate name substituted.

  3. #3
    Star Lounger
    Join Date
    Jan 2001
    Location
    Littleton, Colorado, USA
    Posts
    73
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: List Values for Combo Boxes (A2K, SR1)

    I knew it would be simple, though I didn't think I'd need to resort to code. Thanks!

    Do you ever rest, Hans?

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 28 Times in 28 Posts

    Re: List Values for Combo Boxes (A2K, SR1)

    > Do you ever rest, Hans?

    In case you didn't notice, I was away from the Lounge for 3 days...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •