Full Version: What Is Wrong With This Code
UtterAccess Discussion Forums > Microsoft® Access > Access Q and A
azhar2006
Hi All
What is wrong with this code


Private Sub ComboYears_AfterUpdate()
Stardate = "1/" & Me.ComboMonths.Column(1) & "/" & Me.ComboYears
EndDate = Day(DateSerial((Me.ComboYears.Value), Me.ComboMonths.Column(1) + 1, 1) - 1) & "/" & Me.ComboMonths.Column(1) & "/" & Me.ComboYears

End Sub
theDBguy
Hi,

Since StartDate and EndDate are date/time fields, you'll have to switch the text into U.S. format and convert it into an actual date using the CDate() function. For example:

StartDate = CDate(Me.ComboMonths.Column(1) & "/1/" & Me.ComboYears)

Just my 2 cents... 2cents.gif
John Vinson
What is it doing that you don't want, or not doing that you do? What is the datatype of Stardate?

Note that a Date/Time value is not a text string. If you want these fields to contain a date/time value you would be better off using the DateSerial function directly:

Me.StarDate = DateSerial(Me!cboYears, Me!cboMonths.Column(1), 1)
Me.EndDate = DateSerial(Me!cboYears, Me!cboMonths.Column(1) + 1, 0)

DateSerial is smart enough to treat the zeroth day of a month as the last day of the previous month.
azhar2006
Hi
This is the example
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.