我有以下VBA代码,当我CountryID
时,我试图用另一个表中的CountryID
(ShortText字段)更新列StoreID
(ShortText字段) (ShortText字段)匹配。对于我的生活,虽然我无法使用此代码。
Private Sub btnUpdateColumn2_Click()
Dim t As TableDef
For Each t In CurrentDb.TableDefs
If t.Name Like "PeriodDate_*" Then DoCmd.RunSQL " UPDATE " & t.Name & " SET " & t.Name & ".CountryID = dlookup("[CountryID]", Structure, "[StoreID]" = [" & t.Name & "].[StoreID]) WHERE [" & t.Name & "].StoreID IS NULL; "
Next
End Sub
非常感谢任何帮助。
答案 0 :(得分:1)
为什么在循环TableDef对象时变得复杂?可能不是那么简单,
CurrentDB.Execute "UPDATE theTableName INNER JOIN secondTable ON theTableName.StoreID = secondTable.StoreID_FK SET " & _
"theTableName.CountryID = secondTable.fieldName;"