Userforms and Dates

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I'm getting month and year values from a user form. The months are in the
form January, February, etc. and the years are 2004,2005, 2006. I want to
get the date from the entered values and I've used this equation

PlanDate = Date( Me.cboPlanYear.Value, me.cboPlanMonth.Value,1)

For some reason, it gives me a compile error on this statement. What am I
missing?

Thanks
 
Hi Barb

You must load the combobox with two columns
1 Jan
2 Feb

Hide the first column so you only see the month names
Then use Bound column to read the numbers and not the month name
 
first, Date is what you would use in a worksheet,

DateSerial would be used in VBA.

But either one expects a number for month. for your values use

PlanDate = DateValue(me.cboPlanMonth.Value & " 1, " & Me.cboPlanYear.Value)


or for international considerations

PlanDate = cDate(me.cboPlanMonth.Value & " 1, " & Me.cboPlanYear.Value)
 
Maybe easier to use the listindex it this case

Fill the combo with month names
and it your Dateserial use

me.cboPlanMonth.ListIndex + 1
 

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

Back
Top