Date comparisons on data entry

  • Thread starter Thread starter Tommo
  • Start date Start date
T

Tommo

I would like to compare two date fields on a form at the point that the
second date is entered rather than wait until the user has entered all the
fields and pressed the save button.
I have tried doing the comparison using On Change but the VB code sees the
second field as NULL (when the second date is first entered) and throws a
debug error.
Is there a way of coding this? I am using Access 2007
 
hi Tommo,
I would like to compare two date fields on a form at the point that the
second date is entered rather than wait until the user has entered all the
fields and pressed the save button.
I have tried doing the comparison using On Change but the VB code sees the
second field as NULL (when the second date is first entered) and throws a
debug error.
You haven't posted any code, so I've to guess. You have sub like this:

Private Sub txtDateInput_OnChange()

Dim myDate As Date

myDate = txtDateInput
' or
' myDate = txtDateInput.Value
' or
' myDate = Me![DateField]

End Sub

In all cases the problem is, that the value (!) is changed later. To
test it on the fly, you need to read instead of the value the Text property:


Private Sub txtDateInput_OnChange()

Dim myDate As Date

If IsDate(txtDateInput.Text) Then
myDate = CDate(txtDateInput.Text)
' use it here.
End If

End Sub



mfG
--> stefan <--
 
Stefan,
I tried looking in three large Access manuals but couldn't find anything to
help me.
I tried your code and my form now works. Thank you very much.

Tommo

Stefan Hoffmann said:
hi Tommo,
I would like to compare two date fields on a form at the point that the
second date is entered rather than wait until the user has entered all the
fields and pressed the save button.
I have tried doing the comparison using On Change but the VB code sees the
second field as NULL (when the second date is first entered) and throws a
debug error.
You haven't posted any code, so I've to guess. You have sub like this:

Private Sub txtDateInput_OnChange()

Dim myDate As Date

myDate = txtDateInput
' or
' myDate = txtDateInput.Value
' or
' myDate = Me![DateField]

End Sub

In all cases the problem is, that the value (!) is changed later. To
test it on the fly, you need to read instead of the value the Text property:


Private Sub txtDateInput_OnChange()

Dim myDate As Date

If IsDate(txtDateInput.Text) Then
myDate = CDate(txtDateInput.Text)
' use it here.
End If

End Sub



mfG
--> stefan <--
.
 
Back
Top