I am developing an Access 2003 application using Access as the front end and SQL Server as the back end database.
I have 2 text box input fields for the user to input into
1) a FROM DATE named txtDateFrom in the format MM/DD/YYYY.
2) a To DATE named txtDateTo in the format MM/DD/YYYY.
I use the following routines to validate the 2 dates entered by the user.
The problem is if the user inputs a FROM DATE = 1/1/2008 and a
TO DATE = 06/1/2008.
The system thinks 1/1/2008 is > 06/1/2008 because the first date isn't saved with a month value of 01.
Do you know how I can save the format as a 2 position month field to avoid this problem ?
--------------------------
----------
----------
-
Private Sub txtDateFrom_AfterUpdate()
Dim cn As ADODB.Recordset
Dim str_sql1 As String
Set cn = New ADODB.Recordset
GetDateFrom = Me.txtDateFrom
If IsDate(GetDateFrom) Then
str_sql1 = "Update tblToFromDate Set FromDateVal = " & "'" & GetDateFrom & "'"
DoCmd.RunSQL (str_sql1)
End If
End Sub
Private Sub txtDateFrom_BeforeUpdate(C
ancel As Integer)
Dim strDateFrom
If IsDate(Me.txtDateFrom) Then
strDateFrom = CDate(Format(Me.txtDateFro
m, "mm/dd/yyyy"))
Else
MsgBox "Please enter a valid date in the format mm/dd/yyyy", vbOKOnly, ""
Cancel = True
End If
End Sub
Private Sub txtDateTo_AfterUpdate()
Dim cn As ADODB.Recordset
Dim str_sql1 As String
Set cn = New ADODB.Recordset
GetDateTo = Me.txtDateTo
If IsDate(GetDateTo) Then
str_sql1 = "Update tblToFromDate Set ToDateVal = " & "'" & GetDateTo & "'"
DoCmd.RunSQL (str_sql1)
End If
End Sub
Private Sub txtDateTo_BeforeUpdate(Can
cel As Integer)
Dim strDateTo
If IsDate(Me.txtDateTo) Then
strDateTo = CDate(Format(Me.txtDateTo,
"mm/dd/yyyy"))
Else
MsgBox "Please enter a valid date in the format mm/dd/yyyy", vbOKOnly, ""
Cancel = True
End If
End Sub
Private Function InspectDates() As Boolean
Dim errString As String
errString = ""
If Not IsDate(Nz(Me.txtDateTo)) Then
Me.txtDateTo.SetFocus
errString = errString & "To run reports, enter valid Date To value" & vbCrLf
End If
If Not IsDate(Nz(Me.txtDateFrom))
Then
Me.txtDateFrom.SetFocus
errString = errString & "To run reports, enter valid Date From value" & vbCrLf
End If
If (Me.txtDateFrom > Me.txtDateTo) Then
Me.txtDateFrom.SetFocus
errString = errString & "To run reports, enter Date From <= Date To" & vbCrLf
End If
If errString <> "" Then
InspectDates = False
MsgBox errString, vbOKOnly, ""
Else
InspectDates = True
End If
End Function
Start Free Trial