如何在忽略没有数据的字段的情况下插入表格?

问题描述 投票:-4回答:1

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

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"

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

vba ms-access
1个回答
0
投票

表tbl_Records_of_Violation由此命令插入20列数据。

这20列中的每一列都应该定义为Nullable,

并且每个屏幕值(Me.xxx)需要具有有效数据或空值。

© www.soinside.com 2019 - 2024. All rights reserved.