I created a form in Access 2010 and I fill in the form based on text boxes (B and C) and selection form a combobox (A). The problem is if any of the text box left empty I get “Invalid use of Null” error. I noticed I can avoid this error if I Dim the text boxes as Variant instead of Integer. I am not sure if this is the right solution. Can I change the following script to avoid this error?
Private Sub ABCBoxEnter_Click()
Dim A As String
Dim B As Integer
Dim C As Integer
If Not IsNull(Me!ComboBox.Value) Then
A = Me!ComboBox.Value
B = Afield
C = Bfield
values = "VALUES ("
values = values & "'" & ID & "','" & A & "','" & B & "','" & C & "')"
SQL = "INSERT INTO ContactTable (ID, A, B, C)"
SQL = SQL & values
DoCmd.RunSQL SQL
Me.B.Value = ""
Me.C.Value = ""
End If
End Sub