G
Guest
I'm trying to adde new records with SQL , but it will only work if none of
the values to add is not null or empty. Because the values are saved from
the form's entry, how can I correct it so that it saves all the values? It
doesn't give me an error message, - the record just will not save. Please
help! The following is the code:
Dim db As Database, rsLog As Recordset, strSQL As String
Set db = CurrentDb
strSQL = "SELECT * from NCLog Where"
strSQL = strSQL & "[CARNum] = '" & Me!txtCAR & "'"
Set rsLog = db.OpenRecordset(strSQL, DB_OPEN_DYNASET)
If rsLog.EOF Then
strSQL = "INSERT INTO NCLog"
strSQL = strSQL & "(PONum, POLine, CARNum, DateSaved,"
strSQL = strSQL & "ChassisSN, SupplierID)"
strSQL = strSQL & "VALUES('"
strSQL = strSQL & Me!cboPOKey.Column(1) & "','"
strSQL = strSQL & Me!cboPOKey.Column(2) & "','"
strSQL = strSQL & Me!txtCAR & "','"
strSQL = strSQL & Me!txtDate & "','"
strSQL = strSQL & Me!txtChassisSN & "','"
strSQL = strSQL & Me!txtSupplierID & "');"
MsgBox strSQL
db.Execute strSQL
MsgBox Me!txtCAR & "has been added to the table."
Else
MsgBox "CAR number: " & Me!txtCAR & "already exists.", 48,
"ERROR!"
Me!cboPOKey.SetFocus
End If
rsLog.Close
db.Close
Any help is very much appreciated. Thank you.
Samantha
the values to add is not null or empty. Because the values are saved from
the form's entry, how can I correct it so that it saves all the values? It
doesn't give me an error message, - the record just will not save. Please
help! The following is the code:
Dim db As Database, rsLog As Recordset, strSQL As String
Set db = CurrentDb
strSQL = "SELECT * from NCLog Where"
strSQL = strSQL & "[CARNum] = '" & Me!txtCAR & "'"
Set rsLog = db.OpenRecordset(strSQL, DB_OPEN_DYNASET)
If rsLog.EOF Then
strSQL = "INSERT INTO NCLog"
strSQL = strSQL & "(PONum, POLine, CARNum, DateSaved,"
strSQL = strSQL & "ChassisSN, SupplierID)"
strSQL = strSQL & "VALUES('"
strSQL = strSQL & Me!cboPOKey.Column(1) & "','"
strSQL = strSQL & Me!cboPOKey.Column(2) & "','"
strSQL = strSQL & Me!txtCAR & "','"
strSQL = strSQL & Me!txtDate & "','"
strSQL = strSQL & Me!txtChassisSN & "','"
strSQL = strSQL & Me!txtSupplierID & "');"
MsgBox strSQL
db.Execute strSQL
MsgBox Me!txtCAR & "has been added to the table."
Else
MsgBox "CAR number: " & Me!txtCAR & "already exists.", 48,
"ERROR!"
Me!cboPOKey.SetFocus
End If
rsLog.Close
db.Close
Any help is very much appreciated. Thank you.
Samantha