Use a Combobox to enter a year

Cotty42

Registered User.
Local time
Today, 16:09
Joined
Feb 27, 2014
Messages
102
Hi

I am trying to use a combo box to enter a year value into a query.

I want the values to list each year from, say 2000 to the current year, with a default value of "Current".

Does anyone know a quick way of achieving this or will I have to code each year individually either into a value list or table, and update it each year.

Any help gratefully accepted.

Thanks
 
Hello Cotty42, Welcome to AWF :)

No you can use the following code,
Code:
Private Sub Form_Current()
    Dim iCtr As Long
    Me.yourCombo.RowSourceType = "Value List"
    For iCtr = 2000 To Year(Date)
        Me.yourCombo.AddItem iCtr
    Next
    Me.yourCombo = Year(Date)
End Sub
Change yourCombo, to match your ComboBox name in the form.
 
Worked a treat!!!

Thanks for your help
 

Users who are viewing this thread

Back
Top Bottom