G
Guest
I'm having the worst time trying to fix a problem. I have a table with a
date/fime field (formatted as Short Date). On an unbound form I have the
textbox formatted as a Short Date, but whenever I try to pass the recordset
with an empty date field (the field may be empty due to various reasons) I
get a Type Mismatch. I know it's the date field because when I comment it
out, it works perfectly.
Here's the code:
*****************************************************************
Private Sub btnSavePromoDetails_Click()
On Error GoTo Err_btnSavePromoDetails_Click
' add a new details
' about events, thoughts and anything else
Dim rstANPD As Recordset
' create a recordset reference, then set its properties
Set rstANPD = New ADODB.Recordset
rstANPD.CursorType = adOpenKeyset
rstANPD.LockType = adLockOptimistic
' open the recordset
rstANPD.Open "tblCompanyServices", CurrentProject.Connection
' add a new record to tblCompanyServices
With rstANPD
.AddNew
.Fields("fldPromoID") = (Me!txtPromoIDTen)
.Fields("chkConnected") = (Me!chkConnected)
‘yes/no field
.Fields("fldConnectedDetails") = (Me!txtConnectedDetails)
.Fields("fldEventTitle") = (Me!txtEventTitle)
.Fields("fldPromoDate") = (Me!txtPromoDate) ' short date
Note: Even if I change it to Me!txtPromoDate.Value it doesn’t work
.Fields("fldPromoDetails") = (Me!txtPromoDetails) ' memo fld
.Fields("fldUniqueServices") = (Me!txtUniqueServices) ' memo fld
.Fields("fldUnderstanding") = (Me!txtUnderstanding) ' memo fld
.Update
End With
' clean up
rstANPD.Close
Set rstANPD = Nothing
Exit_btnSavePromoDetails_Click:
Exit Sub
Err_btnSavePromoDetails_Click:
MsgBox "Error in btnSavePromoDetails" & " " & Err.Description & “ “ & "
"Err.Number
Resume Exit_btnSavePromoDetails_Click
End Sub
date/fime field (formatted as Short Date). On an unbound form I have the
textbox formatted as a Short Date, but whenever I try to pass the recordset
with an empty date field (the field may be empty due to various reasons) I
get a Type Mismatch. I know it's the date field because when I comment it
out, it works perfectly.
Here's the code:
*****************************************************************
Private Sub btnSavePromoDetails_Click()
On Error GoTo Err_btnSavePromoDetails_Click
' add a new details
' about events, thoughts and anything else
Dim rstANPD As Recordset
' create a recordset reference, then set its properties
Set rstANPD = New ADODB.Recordset
rstANPD.CursorType = adOpenKeyset
rstANPD.LockType = adLockOptimistic
' open the recordset
rstANPD.Open "tblCompanyServices", CurrentProject.Connection
' add a new record to tblCompanyServices
With rstANPD
.AddNew
.Fields("fldPromoID") = (Me!txtPromoIDTen)
.Fields("chkConnected") = (Me!chkConnected)
‘yes/no field
.Fields("fldConnectedDetails") = (Me!txtConnectedDetails)
.Fields("fldEventTitle") = (Me!txtEventTitle)
.Fields("fldPromoDate") = (Me!txtPromoDate) ' short date
Note: Even if I change it to Me!txtPromoDate.Value it doesn’t work
.Fields("fldPromoDetails") = (Me!txtPromoDetails) ' memo fld
.Fields("fldUniqueServices") = (Me!txtUniqueServices) ' memo fld
.Fields("fldUnderstanding") = (Me!txtUnderstanding) ' memo fld
.Update
End With
' clean up
rstANPD.Close
Set rstANPD = Nothing
Exit_btnSavePromoDetails_Click:
Exit Sub
Err_btnSavePromoDetails_Click:
MsgBox "Error in btnSavePromoDetails" & " " & Err.Description & “ “ & "
"Err.Number
Resume Exit_btnSavePromoDetails_Click
End Sub