【发布时间】:2015-10-05 02:15:00
【问题描述】:
我的 Access VBA 中出现与以下语法不匹配的类型。我正在尝试通过查看是否有任何记录具有查看“Certs”表中的字符串值的日期来更新名为“Billing”的表,例如“2012-07-01”对应于我的表单的 billYear 文本框,例如2012 和我的 billMonth 文本框,例如07. 有没有更好的方法来编写 VBA 或看到错误 - 非常感谢:
Dim sRecert As String
Dim byear As Integer
Dim bmonth As Integer
byear = Me.billYear
bmonth = Me.billMonth
sRecert = "Update Billing set recertifying = -1 where (select certificationExpireDate from certs where Left((certificationExpireDate),4) = " & byear
& " and Mid((certificationExpireDate),6,2) = " & bmonth & ")"
DoCmd.RunSQL sRecert
我可能没有很好地解释它。我创建了一个从我的表单调用的真实查询:
DoCmd.OpenQuery "updateRecert"
我在下面设置了我的 SQL 作为我正在使用的真实日期的测试。它在 SQL Server 中(ODBC 链接)
我的 dbo_certs 表和我的 dbo_billing 表只共享一个可连接字段 peopleID:
UPDATE dbo_Billing AS a INNER JOIN dbo_certs AS b ON a.peopleid = b.peopleid
SET a.recertifying = -1
WHERE b.certificationExpireDate = '2015-08-31 00:00:00.000';
上面给出了数据不匹配错误。 我的底线是我的表单上有两个文本框,可以将数据最好地传递到我的 VBA 代码中:
- billMonth 在这种情况下是 8 因为它是一个整数所以是 一个问题
- billYear 是 2015 年
所以如果 dbo_cert 的字段“certificationExpireDate”是“2015-08-31 00:00:00.000”,我需要将我的 dbo_billing 表的“重新认证”字段更新为 -1,但前提是可以从表单中获取。
【问题讨论】: