I have a table named tblhistory that I have added a new field called FieldB. Either FieldA or FieldB can be null. One has to be null. I have the following code to update tblhistory with values entered on a form, but I am unsure how to make it accept nulls. it keeps giving me an error because there is no value for one of the fields. Can someone please help??
Me.Status = "statusname"
strSQL = " INSERT INTO tblHistory " _
& "([ID], [FieldA], [FieldB], [Status], [Date_of_Change], [End_Change_Date] ) VALUES (" _
& Forms![Form]![ID] & ", '" _
& Forms![Form]![FieldA] & "', " _
& Forms![Form]![FieldB] & "', " _
& "'" & Forms![Form]![Status] & "' , " _
& "#" & Forms![Form]![statusname_Date] & "# , " _
& "#" & Forms![Form]![Scr_End_Date] & "#);"
DoCmd.SetWarnings False
DoCmd.RunSQL strSQL
'DoCmd.Close
DoCmd.SetWarnings True
End If
Me.Status = "statusname"
strSQL = " INSERT INTO tblHistory " _
& "([ID], [FieldA], [FieldB], [Status], [Date_of_Change], [End_Change_Date] ) VALUES (" _
& Forms![Form]![ID] & ", '" _
& Forms![Form]![FieldA] & "', " _
& Forms![Form]![FieldB] & "', " _
& "'" & Forms![Form]![Status] & "' , " _
& "#" & Forms![Form]![statusname_Date] & "# , " _
& "#" & Forms![Form]![Scr_End_Date] & "#);"
DoCmd.SetWarnings False
DoCmd.RunSQL strSQL
'DoCmd.Close
DoCmd.SetWarnings True
End If