Can't get Set Focus to Work

  • Thread starter Thread starter Tina Hudson
  • Start date Start date
T

Tina Hudson

Good day,

I want to prevent a future date being entered for a birth date, but I can't
get this to work. I suspect it has something to do with the MsgBox, but
don't know how to fix. Here is my code:

Private Sub DOB_AfterUpdate()

If ([DOB].Value) > Date Then
MsgBox "The date you entered is a date in the future. Please verify
date and try again. Press OK to continue.", vbExclamation + vbOKOnly,
"Invalid Birth Date"
Me![DOB].SetFocus
End If

End Sub
 
Good day,

I want to prevent a future date being entered for a birth date, but I can't
get this to work. I suspect it has something to do with the MsgBox, but
don't know how to fix. Here is my code:

Private Sub DOB_AfterUpdate()

If ([DOB].Value) > Date Then
MsgBox "The date you entered is a date in the future. Please verify
date and try again. Press OK to continue.", vbExclamation + vbOKOnly,
"Invalid Birth Date"
Me![DOB].SetFocus
End If

End Sub

Use the [DOB] BeforeUpdate event. It has a Cancel argument. Use it.

Private Sub DOB_BeforeUpdate(Cancel as Integer)
If [DOB] > Date Then
MsgBox "The date you entered is a date in the future. Please
verify date and try again. Press OK to continue.", vbExclamation +
vbOKOnly, "Invalid Birth Date"
Cancel = True
End If

End Sub

Focus will remain in the [DOB] control.
 
Thanks! Worked great. I saw an earlier, similar post from someone else
tried this before I posted my question, but I must have done something wrong.
Probably just not following directions.

Have a great weekend.

--
Thanks,
Tina Hudson


fredg said:
Good day,

I want to prevent a future date being entered for a birth date, but I can't
get this to work. I suspect it has something to do with the MsgBox, but
don't know how to fix. Here is my code:

Private Sub DOB_AfterUpdate()

If ([DOB].Value) > Date Then
MsgBox "The date you entered is a date in the future. Please verify
date and try again. Press OK to continue.", vbExclamation + vbOKOnly,
"Invalid Birth Date"
Me![DOB].SetFocus
End If

End Sub

Use the [DOB] BeforeUpdate event. It has a Cancel argument. Use it.

Private Sub DOB_BeforeUpdate(Cancel as Integer)
If [DOB] > Date Then
MsgBox "The date you entered is a date in the future. Please
verify date and try again. Press OK to continue.", vbExclamation +
vbOKOnly, "Invalid Birth Date"
Cancel = True
End If

End Sub

Focus will remain in the [DOB] control.
 
Fred,

Quick question - should I generally always use the Before Update event for
checking data input? Because what I like to do is direct the user back to
the field that they entered incorrect data in.


--
Thanks,
Tina Hudson


fredg said:
Good day,

I want to prevent a future date being entered for a birth date, but I can't
get this to work. I suspect it has something to do with the MsgBox, but
don't know how to fix. Here is my code:

Private Sub DOB_AfterUpdate()

If ([DOB].Value) > Date Then
MsgBox "The date you entered is a date in the future. Please verify
date and try again. Press OK to continue.", vbExclamation + vbOKOnly,
"Invalid Birth Date"
Me![DOB].SetFocus
End If

End Sub

Use the [DOB] BeforeUpdate event. It has a Cancel argument. Use it.

Private Sub DOB_BeforeUpdate(Cancel as Integer)
If [DOB] > Date Then
MsgBox "The date you entered is a date in the future. Please
verify date and try again. Press OK to continue.", vbExclamation +
vbOKOnly, "Invalid Birth Date"
Cancel = True
End If

End Sub

Focus will remain in the [DOB] control.
 
Back
Top