Date in combox box in form

x18access

Registered User.
Local time
Today, 15:51
Joined
Jan 5, 2014
Messages
14
Hi all,

i am looking to generate a list of dates in a combo box. I want the dates to be from 1 week ago to today. And all other attempted entries to be invalid. This means the user could only select one of those dates, with any other entry returning an error

How would i go about doing this?

many thanks as always!
 
use a bit of vba to populate the combo rowsource - it will be something like

Code:
dim i as integer
 
for i=0 to 6
    myCombo.Rowsource=datediff('d',-i,date()) & ";"
next i
Note you need to set your combobox to value list rather than table/query and limit to list=yes

Edit: amended the range to 0 to 6
 
CJ London

the code is not working
It returns the error : compile error, expected expression, at the ('d'.

Why is it doing this, can any body offer a solution?

thanks!
 
my mistake, wrote it in a bit of a hurry - try


Code:
dim i as integer

for i=0 to 6
    myCombo.Rowsource=myCombo.Rowsource & datediff("d",-i,date()) & ";"
next i
Not sure where you have put the code, but suggest in the form open event
 
Wrong function.
You need the DateAdd function.
 

Users who are viewing this thread

Back
Top Bottom