date entry validation problem

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

Guest

This code does not seem to trigger. Any ideas why?
The fields are text feilds formatted dd/mm/yy
I assume this may be my problem.
Any recommendations on how I can get this to work?


Private Sub ElecReturnAcknowledgedDate_LostFocus()

' Date validation

If Me.ElecReturnAcknowledgedDate.Value < Me.ElecReturnSubmittedDate.Value Then
MsgBox "Your acknowledgement date is before the submitted date.", _
vbExclamation, "Unexpected data"
End If

End Sub
 
Your code indicates that you want to compare 2 values. In Windows, you have
no idea if the use will click on a text box (they may never visit it), or in
what order they will click on the controls.

Therefore, you need to use the BeforeUpdate event of the *form* for
validation that involves comparing controls. Cancel the event to prevent the
bad data being written.

Private Sub Form_BeforeUpdate(Cancel As Integer)
If Me.ElecReturnAcknowledgedDate < Me.ElecReturnSubmittedDate Then
Cancel = True
MsgBox "Your ack...
End If
End Sub

Another other reason the MsgBox will not fire would be if either of the
dates were blank.

Occassionally, you find that the Properties box is missing the [Event
Procedure] on the Events tab, which will also mean the code will not fire.
 
Excellent. Thanks Allen.

--
I may not know VBA inside out, but from the outside I am looking in.
Dylan Moran - Melbourne Australia


Allen Browne said:
Your code indicates that you want to compare 2 values. In Windows, you have
no idea if the use will click on a text box (they may never visit it), or in
what order they will click on the controls.

Therefore, you need to use the BeforeUpdate event of the *form* for
validation that involves comparing controls. Cancel the event to prevent the
bad data being written.

Private Sub Form_BeforeUpdate(Cancel As Integer)
If Me.ElecReturnAcknowledgedDate < Me.ElecReturnSubmittedDate Then
Cancel = True
MsgBox "Your ack...
End If
End Sub

Another other reason the MsgBox will not fire would be if either of the
dates were blank.

Occassionally, you find that the Properties box is missing the [Event
Procedure] on the Events tab, which will also mean the code will not fire.
 
Dylan Moran said:
Excellent. Thanks Allen.

--
I may not know VBA inside out, but from the outside I am looking in.
Dylan Moran - Melbourne Australia


Allen Browne said:
Your code indicates that you want to compare 2 values. In Windows, you have
no idea if the use will click on a text box (they may never visit it), or in
what order they will click on the controls.

Therefore, you need to use the BeforeUpdate event of the *form* for
validation that involves comparing controls. Cancel the event to prevent the
bad data being written.

Private Sub Form_BeforeUpdate(Cancel As Integer)
If Me.ElecReturnAcknowledgedDate < Me.ElecReturnSubmittedDate Then
Cancel = True
MsgBox "Your ack...
End If
End Sub

Another other reason the MsgBox will not fire would be if either of the
dates were blank.

Occassionally, you find that the Properties box is missing the [Event
Procedure] on the Events tab, which will also mean the code will not fire.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Dylan Moran said:
This code does not seem to trigger. Any ideas why?
The fields are text feilds formatted dd/mm/yy
I assume this may be my problem.
Any recommendations on how I can get this to work?


Private Sub ElecReturnAcknowledgedDate_LostFocus()

' Date validation

If Me.ElecReturnAcknowledgedDate.Value < Me.ElecReturnSubmittedDate.Value
Then
MsgBox "Your acknowledgement date is before the submitted date.", _
vbExclamation, "Unexpected data"
End If

End Sub
 
I'm trying to use your explanation here in comparing 2 controls. I have 2
calculated fields, one in a form and one from the subform. I'm comparing the
calculated ending dates as follows:

Private Sub contract_end_date_BeforeUpdate(Cancel As Integer)

If Me.CalcEndDate([Me.Term_type], [me.Term_mos], [me.Acceptance_date]) >=
[Forms]![frmEffective_contract]![Contract_end_date] Then
Cancel = True
MsgBox "Please revise the contract term. The ending date on your subform is
greater than the main contract's date."
End If
End Sub

Why isn't it triggering the msgbox when the subform's ending date is
1/14/2006 and the main form's ending date is 12/31/2005?

Thank you,
gg





Dylan Moran said:
Excellent. Thanks Allen.

--
I may not know VBA inside out, but from the outside I am looking in.
Dylan Moran - Melbourne Australia


Allen Browne said:
Your code indicates that you want to compare 2 values. In Windows, you have
no idea if the use will click on a text box (they may never visit it), or in
what order they will click on the controls.

Therefore, you need to use the BeforeUpdate event of the *form* for
validation that involves comparing controls. Cancel the event to prevent the
bad data being written.

Private Sub Form_BeforeUpdate(Cancel As Integer)
If Me.ElecReturnAcknowledgedDate < Me.ElecReturnSubmittedDate Then
Cancel = True
MsgBox "Your ack...
End If
End Sub

Another other reason the MsgBox will not fire would be if either of the
dates were blank.

Occassionally, you find that the Properties box is missing the [Event
Procedure] on the Events tab, which will also mean the code will not fire.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Dylan Moran said:
This code does not seem to trigger. Any ideas why?
The fields are text feilds formatted dd/mm/yy
I assume this may be my problem.
Any recommendations on how I can get this to work?


Private Sub ElecReturnAcknowledgedDate_LostFocus()

' Date validation

If Me.ElecReturnAcknowledgedDate.Value < Me.ElecReturnSubmittedDate.Value
Then
MsgBox "Your acknowledgement date is before the submitted date.", _
vbExclamation, "Unexpected data"
End If

End Sub
 
gg, suggest you start a new thread. it's doubtful whether anyone will notice
this post when the thread is over a month old. (the only reason i saw it is
because i've been too busy to clear out my old "watched" threads. <g> and
btw, that's the same reason why i can't try to help you out with this
question myself, sorry.)


gg said:
I'm trying to use your explanation here in comparing 2 controls. I have 2
calculated fields, one in a form and one from the subform. I'm comparing the
calculated ending dates as follows:

Private Sub contract_end_date_BeforeUpdate(Cancel As Integer)

If Me.CalcEndDate([Me.Term_type], [me.Term_mos], [me.Acceptance_date]) >=
[Forms]![frmEffective_contract]![Contract_end_date] Then
Cancel = True
MsgBox "Please revise the contract term. The ending date on your subform is
greater than the main contract's date."
End If
End Sub

Why isn't it triggering the msgbox when the subform's ending date is
1/14/2006 and the main form's ending date is 12/31/2005?

Thank you,
gg





Dylan Moran said:
Excellent. Thanks Allen.

--
I may not know VBA inside out, but from the outside I am looking in.
Dylan Moran - Melbourne Australia


Allen Browne said:
Your code indicates that you want to compare 2 values. In Windows, you have
no idea if the use will click on a text box (they may never visit it), or in
what order they will click on the controls.

Therefore, you need to use the BeforeUpdate event of the *form* for
validation that involves comparing controls. Cancel the event to prevent the
bad data being written.

Private Sub Form_BeforeUpdate(Cancel As Integer)
If Me.ElecReturnAcknowledgedDate < Me.ElecReturnSubmittedDate Then
Cancel = True
MsgBox "Your ack...
End If
End Sub

Another other reason the MsgBox will not fire would be if either of the
dates were blank.

Occassionally, you find that the Properties box is missing the [Event
Procedure] on the Events tab, which will also mean the code will not fire.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

This code does not seem to trigger. Any ideas why?
The fields are text feilds formatted dd/mm/yy
I assume this may be my problem.
Any recommendations on how I can get this to work?


Private Sub ElecReturnAcknowledgedDate_LostFocus()

' Date validation

If Me.ElecReturnAcknowledgedDate.Value < Me.ElecReturnSubmittedDate.Value
Then
MsgBox "Your acknowledgement date is before the submitted date.", _
vbExclamation, "Unexpected data"
End If

End Sub
 

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

Similar Threads


Back
Top