problem clearing text box value

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

here's the code:

Private Sub spFinishDate_BeforeUpdate(Cancel As Integer)

If Me.spFinishDate.Value < Me.spStartDate Then
MsgBox "Finish Date must be after start date", vbCritical
spFinishDate.Value = ""
End If

End Sub

When I enter a finish date that precedes the start date, I get the message
box. However, instead of the finish date value clearing, I get run-time
error stating "The macro or function set to the BeforeUpdate or
ValidationRule property is preventing access from saving data in the field"

Can anyone explain what I'm doing wrong here?

Thanks!
 
here's the code:

Private Sub spFinishDate_BeforeUpdate(Cancel As Integer)

If Me.spFinishDate.Value < Me.spStartDate Then
MsgBox "Finish Date must be after start date", vbCritical
spFinishDate.Value = ""
End If

End Sub

When I enter a finish date that precedes the start date, I get the message
box. However, instead of the finish date value clearing, I get run-time
error stating "The macro or function set to the BeforeUpdate or
ValidationRule property is preventing access from saving data in the field"

Can anyone explain what I'm doing wrong here?

Thanks!

No point in clearing the date entry as the user will not be able to
confirm the improper date. Perhaps it was the first date entry that
was incorrect.
Just cancel the update. Let the user then see and change the entered
value(s) as needed..

Private Sub spFinishDate_BeforeUpdate(Cancel As Integer)

If Me.spFinishDate.Value < Me.spStartDate Then
MsgBox "Finish Date must be after start date", vbCritical
Cancel = True
End If

End Sub
 
Try this

Private Sub spFinishDate_BeforeUpdate(Cancel As Integer)
If Me.spFinishDate.Value > Me.spStartDate Then
MsgBox "Finish Date must be after start date", vbOKOnly, "title"
spFinishDate= ""
End If
End Sub
 
ProjectUser said:
here's the code:

Private Sub spFinishDate_BeforeUpdate(Cancel As Integer)

If Me.spFinishDate.Value < Me.spStartDate Then
MsgBox "Finish Date must be after start date", vbCritical
spFinishDate.Value = ""
End If

End Sub

When I enter a finish date that precedes the start date, I get the message
box. However, instead of the finish date value clearing, I get run-time
error stating "The macro or function set to the BeforeUpdate or
ValidationRule property is preventing access from saving data in the
field"

Can anyone explain what I'm doing wrong here?

Thanks!
 

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

Back
Top