I have a form, myForm, that includes a subform, mySubform
. The records in mySubform
have a many to one relationship with the record source of the myForm
, as expected, and There is a combobox in mySubform
, myCombo
, whose values is linked to one of the columns of the record source of mySubform
.
I have been having difficulty to delete a record in mySubform
, by erasing the current value in myCombo
. I have put the code below under the OnChange
event of myCombo
(after trying many different alternatives).
Please not that I have simplified the delete query and the actual one works fine in the back-end (SQL Server). However, after performing the delete operation, I get this error when the execution reaches Me.Requery
:
Error 3162 You tried to assign a Null value to a variable that is not a Variant data type.
Also, after having the degugger skip the Me.Requery
and going back to the form, the deleted record shows "#DELETED" in every combobox and textbox for that particular record, and mySubform
is not any good beyond that point.
I have looked up very many resources and tried different statements instead of Me.Requery, but none has worked so far. Help is much appreciated.
Private Sub myCombo_Change()
If IsNull(Me.myCombo.Text) Or Me.myCombo.Text = vbNullString Then
Dim strSql As String
strSql = "DELETE FROM mySubformRecordSource WHERE PrimaryKeyColumn= " & theCurrentPrimaryKeyValueForTheValueIn_MyCombo
CurrentDb.Execute strSql
Me.Requery
End If
End Sub