ListBox with Years

D

DS

I need to make a Listbox with the current year in it, and the next 10
years. Like This:
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016

Then Next Year the rowsource would be:

2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017

Each year the rowsource would move up one year. How can I do this? Any
help appreciated.
Thanks
DS
 
D

Dirk Goldgar

DS said:
I need to make a Listbox with the current year in it, and the next 10
years. Like This:
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016

Then Next Year the rowsource would be:

2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017

Each year the rowsource would move up one year. How can I do this?
Any help appreciated.

Create a table named, say, Iotas, with a single field, a Long Integer
field named Iota. Create 10 records in this table, with values for Iota
from 0 to 9.

Now you can create your rowsource query with SQL like this:

SELECT Year(Date())+Iota AS xYear
FROM tblIotas
WHERE Iota<10;

You can use this Iotas table in other circumstances, too, to generate
any number of records you want. To create 10 records, include the table
once in the query, but don't join it to anything. To create 100
records, include it twice. To create 1000 records, include it three
times.

Or, if you frequently need to generate a larger number of records, put
100 records in Iotas. Then you only need to include it twice in a query
to create 10,000 records.
 
D

DS

Dirk said:
Create a table named, say, Iotas, with a single field, a Long Integer
field named Iota. Create 10 records in this table, with values for Iota
from 0 to 9.

Now you can create your rowsource query with SQL like this:

SELECT Year(Date())+Iota AS xYear
FROM tblIotas
WHERE Iota<10;

You can use this Iotas table in other circumstances, too, to generate
any number of records you want. To create 10 records, include the table
once in the query, but don't join it to anything. To create 100
records, include it twice. To create 1000 records, include it three
times.

Or, if you frequently need to generate a larger number of records, put
100 records in Iotas. Then you only need to include it twice in a query
to create 10,000 records.
Ok Dirk, I came up with this:

With Me.ListYrs
.RowSourceType = "Value List"
.RowSource = Now(), Now()+1, Now()+2
.ColumnCount = 1
.ColumnWidth = 1.5 * 1440
.Requery
End With

2 Problems, The first is that I need the year 2006 only not 08/09/2006
the second is that I could only do one Now() I can't find the syntax for
adding more than one. This way I don't have to add a table and have
several records as well, any help appreciated.
Thanks
DS
 
D

DS

DS said:
Ok Dirk, I came up with this:

With Me.ListYrs
.RowSourceType = "Value List"
.RowSource = Now(), Now()+1, Now()+2
.ColumnCount = 1
.ColumnWidth = 1.5 * 1440
.Requery
End With

2 Problems, The first is that I need the year 2006 only not 08/09/2006
the second is that I could only do one Now() I can't find the syntax for
adding more than one. This way I don't have to add a table and have
several records as well, any help appreciated.
Thanks
DS
OK this seems like it will work.

With Me.ListYrs
..RowSourceType = "Value List"
..RowSource = Format(Date, "yyyy") + 1
..ColumnCount = 1
..ColumnWidth = 1.5 * 1440
..Requery
End With

The Only problem now is how do I add more years to the rowsource...?
..RowSource = "Format(Date, "yyyy"),Format(Date, "yyyy") + 1"
Doesn't Work
..RowSource = "Format(Date, "yyyy");Format(Date, "yyyy") + 1"
Doesn't Work
..RowSource = Format(Date, "yyyy"),Format(Date, "yyyy") + 1
Doesn't Work

Any clue what the Syntax is?
Thanks
DS
 
D

DS

Dirk said:
Create a table named, say, Iotas, with a single field, a Long Integer
field named Iota. Create 10 records in this table, with values for Iota
from 0 to 9.

Now you can create your rowsource query with SQL like this:

SELECT Year(Date())+Iota AS xYear
FROM tblIotas
WHERE Iota<10;

You can use this Iotas table in other circumstances, too, to generate
any number of records you want. To create 10 records, include the table
once in the query, but don't join it to anything. To create 100
records, include it twice. To create 1000 records, include it three
times.

Or, if you frequently need to generate a larger number of records, put
100 records in Iotas. Then you only need to include it twice in a query
to create 10,000 records.
OK Dirk, You Did it!!!!! I misunderstood what it would do. That is
some really neat programming that you did there! Once again my many
thanks and my humble apologies!
Thanks
DS
 

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

Similar Threads


Top