Date comparisons on data entry

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
 
S

Stefan Hoffmann

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 <--
 
T

Tommo

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 <--
.
 

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