至少你需要做这样的事情:
Dim SQL as string
SQL = "INSERT INTO tblAudit ([RecordID], [AuditWho], [AuditWhen], [AuditWhat], [AuditFrom], [AuditTo]) VALUES ('1', '2','" & Now() & "', 'ClientName' , '" & Me.ClientName.Value & "', '" & Me.clientNameTextBox.Value & "')"
db.Execute SQL
为了更“健壮”,您应该在尝试执行插入之前为AuditFrom
和AuditTo
值声明变量并验证输入的数据是否“正常”:
Dim SQL as string
dim strAuditFrom as string
Dim strAuditTo As String
strAuditFrom = Me.ClientName.Value & ""
strAuditTo = Me.ClientNameTextBox.Value & ""
if strAuditTo = vbNullString then
'Alert the user or throw an error perhaps?
end if
sql = "INSERT INTO tblAudit ([RecordID], [AuditWho], [AuditWhen], [AuditWhat], [AuditFrom], [AuditTo]) VALUES ('1', '2','" & Now() & "', 'ClientName' , '" &strAuditFrom & "', '" & strAuditTo & "')"
db.Execute sql