48Highlander
Technical User
When I enter 31 Sep 2001 into a date field, I get the access error "The value you entered isn't valid for this field."
How do I trap this error?
Bill J
How do I trap this error?
Bill J
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
On Error GoTo Err_YourDateField_BeforeUpdate_Error
Err_YourDateField_BeforeUpdate_Error:
MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure YourDateField_BeforeUpdate of VBA Document Form_YourForm"
If Err.Number = 2113 Then
Take desired action (whatever you want to do)
End If
Function sRecordAccessErrorMsg()
Dim ADOcnn As ADODB.Connection
Dim ADOrst As ADODB.Recordset
Dim intCounter As Long
Dim intErrornumber As Long
Dim strErrorText As String
Set ADOcnn = CurrentProject.Connection
Set ADOrst = New ADODB.Recordset
ADOrst.Open "tblErrorsAndDescriptions", ADOcnn, adOpenDynamic, adLockOptimistic
With ADOrst
For intCounter = 0 To 32767
.AddNew
!ErrorNumber = intCounter
If IsNull(AccessError(intCounter)) Then
!ErrorDescription = "No Error"
ElseIf AccessError(intCounter) = "" Then
!ErrorDescription = "No Error"
Else
!ErrorDescription = AccessError(intCounter)
End If
.Update
Next intCounter
End With
MsgBox "Completed enumerating errors to the table."
End Function
Private Sub txtBirthdate_BeforeUpdate(Cancel As Integer)
On Error GoTo err_txtBirthdate_BeforeUpdate
Dim LatestBirthYear As Integer
LatestBirthYear = DatePart("yyyy", Date) - 16
If Me.txtBirthdate < #1/1/1914# Or DatePart("yyyy", Me.txtBirthdate) > LatestBirthYear Then
MsgBox "Invalid date: Date is earlier than 1914 or person is younger than 16", vbInformation + vbOKOnly, "Error"
Me.txtBirthdate.Undo
Cancel = True
End If
Exit_txtBirthdate_BeforeUpdate:
Exit Sub
err_txtBirthdate_BeforeUpdate:
If Err.Number = 2113 Then
MsgBox "Invalid date entered", vbOKOnly, "Error"
Me.txtBirthdate.Undo
Else
MsgBox Err.Description
Resume Exit_txtBirthdate_BeforeUpdate
End If
End Sub