Vba 如何在忽略没有数据的字段时插入到表中?

Vba 如何在忽略没有数据的字段时插入到表中?,vba,ms-access,Vba,Ms Access,我不想在表中插入数据,但并非所有字段都需要填写,有些字段只是可选的 CurrentDb.Execute "INSERT INTO tbl_Records_of_Violation(Serial_Number,Badge,Rank,Lastname,Firstname,Middlename,Qualifier,Gender,Birthdate,Date_Ent_Svc,Address,MotherUnit,Unit,Date_of_Commission,Reporting_Officer,Repo

我不想在表中插入数据,但并非所有字段都需要填写,有些字段只是可选的

CurrentDb.Execute "INSERT INTO tbl_Records_of_Violation(Serial_Number,Badge,Rank,Lastname,Firstname,Middlename,Qualifier,Gender,Birthdate,Date_Ent_Svc,Address,MotherUnit,Unit,Date_of_Commission,Reporting_Officer,Report_to_Supervisor,Approving_Authority,Punishment,Remarks,Violation1) VALUES ('" & Me.Serial_Number & "','" & Me.Badge & "','" & Me.Rank & "','" & Me.Lastname & "','" & Me.Firstname & "','" & Me.Middlename & "','" & Me.Qualifier & "','" & Me.Gender & "','" & Me.Birthdate & "','" & Me.Date_Ent_Svc & "','" & Me.Address & "','" & Me.MotherUnit & "','" & Me.Unit & "','" & Me.Date_of_Commission & "','" & Me.Reporting_Officer & "','" & Me.Report_to_Supervisor & "','" & Me.Approving_Authority & "','" & Me.Punishment & "','" & Me.Remarks & "'," & Me.Violation1 & ")"

MsgBox "Record has been updated", vbInformation, "Record Information"

我希望,即使其中一个字段为空,它也会保存在我的表中。

表tbl\u记录\u冲突有20列数据被此命令插入

这20列中的每一列都应定义为可空


每个屏幕值Me.xxx都需要有有效的数据或空值。

我不确定我是否理解这个问题,但是参数化查询不是更好吗?这样,您就可以为缺少但不是必需的任何内容提供空值。看起来您正在使用表单。那么为什么不把表单绑定到表上呢?然后,您可以用更少的代码做更多的事情,它将按照您需要的方式工作。