How do I populate a combo box with a list of dates

M

Mike

I want to allow users to select a date from a list of dates beginning with
today and ending atter approximately 30 days. If anyone can help I would
appreciate it
 
R

Rick B

Seems like it would be easier to type a date, then scroll through a list of
thirty dates.

Or, I'd use a pop-up calendar control.

I can't imagine it would be easier to select a date from a drop down list
unless the list only contained some valid dates. For example, if it only
included Saturdays for the next year.

What you are asking to do is similar to putting the numbers 1 though 30 in a
drop down field. It just isn't done.

Rick B
 
M

Mike

Thank you, my intention was to allow the user to type the day part of the day
and allow the auto expand to fill in the rest to reduce typing. I presume I
will have to be happy with a date picker control
 
T

Tim Ferguson

Thank you, my intention was to allow the user to type the day part of
the day and allow the auto expand to fill in the rest to reduce
typing. I presume I will have to be happy with a date picker control

You could probably do something fancy with the Change event:

Public sub txtSomeDate_Change()

dim varTemp as variant ' allow coercion

' get a temporary copy
vartemp = txtsomedate.text

' if it's a number, attempt to expand it
if isnum(varTemp) then

' is it a valid day-of-a-month?
if 0 < vartemp and vartemp < 32 then
' try adding today's month and year after it
vartemp = vartemp & format(Date(), "\/mm\/yyyy")

' put it back in the control
txtSomeDate.Text = varTemp
' and highlight the bit we added
txtSomeDate.SelStart = Len(varTemp-8)
txtSomeDate.SelLength = 8

End if

Else
' carry on with other inputs

End If

End Sub


you need to be pretty clear about how you are going to interpret the user's
input and what to do with it. It's not hard to get badly in the way of
typing something quite legal.

HTH


Tim F
 

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