首页 > 解决方案 > 插入表格中的vba值和表格中的值

问题描述

我想要发生的是,我将来自联系人的 ID 附加到 Contact_Attendance,其中记录不是非活动的并且(这是问题区域)将 Text1 中的值放入 Contact_Attendance 上的 EffectiveDate 字段(日期/时间)

Option Compare Database

选项显式

Private Sub Command5_Click() Dim strSqlInsert As String Dim strsqlUpdate As String Dim Effectivedate As Date

strSqlInsert = "INSERT INTO contacts_attendance (contactID) SELECT ID from contacts where inactive = false;"
strsqlUpdate = "UPDATE contacts_attendance SET effectivedate = ' " & Text1 & "'"

DoCmd.SetWarnings False
DoCmd.RunSQL strSqlInsert

'I think I need a statement here to check if effectivedate is null (implies its a new insert) then only populate those records
'Need help writing it.
DoCmd.RunSQL strsqlUpdate
DoCmd.SetWarnings True

结束子

用于视觉的屏幕截图 带有 text1 日期和按钮的表单,代码连接到 表结果与上面的代码。

标签: vbasql-insert

解决方案


推荐阅读