Date in combox box in form (1 Viewer)

x18access

Registered User.
Local time
Yesterday, 22:18
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!
 

CJ_London

Super Moderator
Staff member
Local time
Today, 06:18
Joined
Feb 19, 2013
Messages
16,668
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
 

x18access

Registered User.
Local time
Yesterday, 22:18
Joined
Jan 5, 2014
Messages
14
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!
 

CJ_London

Super Moderator
Staff member
Local time
Today, 06:18
Joined
Feb 19, 2013
Messages
16,668
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
 

Galaxiom

Super Moderator
Staff member
Local time
Today, 15:18
Joined
Jan 20, 2009
Messages
12,856
Wrong function.
You need the DateAdd function.
 

Users who are viewing this thread

Top Bottom