Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Access 2010 - Combo box values 1

Status
Not open for further replies.

ICCIIT

Technical User
Jul 21, 2003
62
GB
On my form I wish to have an unbound dynamic combo box that is limited to 2 values only...

The start date of the current week
The start date of the next week
(both being Mondays)

Naturally as time moves on, the requirement is that these dates will move with it..

I cannot find a way to populate these options in the value list with a DateSerial function

Anyone able to give me some pointers?

Thanks

 
How about:

Code:
Dim datMonday As Date

datMonday = Date

Do Until Weekday(datMonday) = vbMonday
    datMonday = datMonday - 1
Loop

With cboMondays
    .AddItem datMonday
    .AddItem datMonday + 7
    .ListIndex = 0
End With

Have fun.

---- Andy

A bus station is where a bus stops. A train station is where a train stops. On my desk, I have a work station.
 
Hi Andy
Cannot get this to work at the moment, I have placed this code in the on-click event of the combo but it does not populate the list... it does not error either so not sure what is happening..

The combo Row source is set to Value list
and Rowsource is empty
Bound column=1

Thanks
 
Andy
OK.... some success...

Its now in my FormLoad event
it gives me error 7777

"You have used the Listindex property incorrectly"

But when I end the error, the combo shows me the 2 dates....

so nearly there!




(
 
Could you try this:
1. Start a new Access with one UserForm
2. Place a combo box, name it cboMonday (you may want to set it to List so you cannot type in it)
3. Place a command button on the Form
4. Place the code in the Click event of the command button.
5. Run the application, click on the button

You may also try this in Excel (UserForm, combo box, command button, etc.), it should work the same way.


Have fun.

---- Andy

A bus station is where a bus stops. A train station is where a train stops. On my desk, I have a work station.
 
OK.... I have now removed the .listindex=0 from within the With statement and its all working!!

very elegant solution

Thanks
 
Revised code

Now in the Form Current event...

Code:
Private Sub Form_Current()
Dim datMonday As Date

datMonday = Date

Do Until Weekday(datMonday) = vbMonday
    datMonday = datMonday - 1
Loop

With cboMondays
    .AddItem datMonday
    .AddItem datMonday + 7
    
End With
 
instead of
[tt].ListIndex = 0[/tt]

you may try
[tt].ItemData(0)[/tt]

Have fun.

---- Andy

A bus station is where a bus stops. A train station is where a train stops. On my desk, I have a work station.
 
O, just to be on the safe side, Clear it before populating.

Code:
With cboMondays
    .Clear
    .AddItem datMonday
    .AddItem datMonday + 7
    .ItemData(0
End With

I'm not sure how often the Curent event fires.

Have fun.

---- Andy

A bus station is where a bus stops. A train station is where a train stops. On my desk, I have a work station.
 
Thanks Andy... a deserved star....I can see many uses for this....
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top