Text fields to dates

T

Terri

I have two fields. One contains a month (ex. January). The other contains a
year (ex. 2008). I would like to use these fields to develop the date for
the last day of the year and month (ex. 20080131) in a date field that can be
compared to another date. Any suggestions?
 
D

DanRoss

Here's an example you should be able to accomidate into your situation.

Dim sMonth
Dim sYear
Dim sDate

sMonth = "December"
sYear = "2008"
sDate = CDate(sMonth & " 1, " & sYear)

Debug.Print sDate ' This is the date as is.
sDate = DateAdd("M", 1, sDate)
Debug.Print sDate ' Add a month so you have the first day of the next
month
sDate = DateAdd("d", -1, sDate)
Debug.Print sDate ' Subtract a day so you have the last day of the
preceding (or selected month)

Hope this helps.
 

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