Something like this:
Code:
Dim sSQL As String
Dim sSQLVALUES As String
sSQL = "INSERT INTO tblPATUCASES ("
sSQLVALUES = "VALUES ("
If Len(Trim(Me.CTN & "")) = 0 Then
sSQLVALUES = sSQLVALUES & Me.CTN & ", "
End If
If Len(Trim(Me.City_Where_Crime_Occurred & "")) = 0 Then
sSQL = sSQL & " City_Where_Crime_Occurred,"
sSQLVALUES = sSQLVALUES & Me.City_Where_Crime_Occurred & ", "
End If
' .
' .
' you have 20 controls, so
' .there will be a total of 20 tests for NULL controls
' .
' .
If Len(Trim(Me.Notes & "")) = 0 Then
sSQL = sSQL & " Notes,"
sSQLVALUES = sSQLVALUES & "'" & Me.Notes & "', "
End If
'Then remove the last comma from both sSQL & sSQLVALUES
'and add a closing parenthisis for both sSQL & sSQLVALUES
'Then
sSQL = sSQL & " " & sSQLVALUES
'check to see if insert statement formed correctly
Debug.Print sSQL
CurrentDb.Execute sSQL, dbFailOnError
I don't know what the field types are, so you will need to add the proper delimiters.
Oops, I see that Paul posted first............