How to change January 2008 to 1/1/2008

C

Chuck M

Hi - I'm a bit of a VBA novice. I need to take the result of a combobox
selection of month and year and convert it to mm/dd/yyyy format where dd is
always the first day of the month. Can anyone help?
 
S

Stuart McCall

Chuck M said:
Hi - I'm a bit of a VBA novice. I need to take the result of a combobox
selection of month and year and convert it to mm/dd/yyyy format where dd
is
always the first day of the month. Can anyone help?

Dim selDate As Date

selDate = Cdate(Me.MonthCombo.Value & _
"/01/" & _
Me.YearCombo.Value)

The above code assumes that it is located in the form's module.
 
C

Chuck M

Stuart - Thanks for the quick reply. I did some additional research after my
original post and found this solution:

a = Me.cboCycleToBill
dt = Format(a, "mm/dd/yyyy")

This seems to give me the desired result. Do you see anything improper about
this solution? I am using dt in a where clause.
 
J

John Spencer

If your combobox value is something like "January 2008", you can use CDate
which will convert that string to a date value of 1/1/2008.

CDate(Forms![NameofForm]!cboCycleToBill)

If you need that as a string in the format mm/dd/yyyy you can then apply the
format to the string.

John Spencer
Access MVP 2002-2005, 2007-2008
The Hilltop Institute
University of Maryland Baltimore County
 

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