combo box containing years

G

Guest

Hello,
I have a form with a combo box. I want the combo box to contain years
between 2000 and 2020, and its default value to be the current year. I don't
know how to do this...
Can any body please help?

And another question:
I have a form with 2 combo boxes. Combo box 1 contains 3 values from which
the user has to choose. I want combo box 2 to contain values according to the
value chosen in combo box 1. lets say the user has chosen from combo box 1
the value "a", then I want combo box 2 to contain options d, e, and f. but if
the user chooses from combo box 1 the value "b", then I want combo box 2 to
contain the options g, h, and i. Is there any easy way achieving this (even
using vb)?

thank you,
 
D

Douglas J. Steele

You could build a table that contains the values 2000 through 2020 and base
the combobox on that table, or you can base the combo box on a user-defined
function that has an extremely specific setup:

Function ListYears( _
fld As Control, _
id As Variant, _
row As Variant, _
col As Variant, _
code As Variant _
) As Variant

Select Case code
Case acLBInitialize
ListYears = True
Case acLBOpen
ListYears = Timer
Case acLBGetRowCount
ListYears = 21
Case acLBGetColumnCount
ListYears = 1
Case acLBGetColumnWidth
ListYears = -1
Case acLBGetValue
ListYears = 2000 + row
End Select
End Function

You'd set the Row Source Type property for the combo to the name of the
function and leave the Row Source property blank.
 
G

Guest

Thank you very much. It works wonderfully.
How do I set the default value to be the current year?
 
S

Steven Greenberg

Thank you very much. It works wonderfully.
How do I set the default value to be the current year?

I would just set the value of the combobox to year(now) when the form is
loaded.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top