我有下表(tmpManifest-ID为PK)-数据是从条形码扫描仪填充的,因此我无法控制其创建方式:
但是,我需要填充Box列,如下所示-它需要知道何时更改为正确的Box:
通过更新查询实现此目标的最佳方法是什么?
答案 0 :(得分:2)
尝试此解决方案-将遍历每条记录并逐一更新。
Dim SQL As String, sUPC As String, sID As String
Dim rs As DAO.Recordset
Set rs = CurrentDb.OpenRecordset("SELECT [ID], [UPC], [Description] FROM [tmpManifest] ORDER BY [ID] ASC")
If Not (rs.EOF And rs.BOF) Then
Do While Not rs.EOF
sID = CStr(rs![ID])
If IsNull(rs![Description]) Then
SQL = "UPDATE [tmpManifest] SET [BOX] = '" & sUPC & "' WHERE [ID] = " & sID
CurrentDb.Execute SQL
Else
sUPC = CStr(rs![UPC])
SQL = "UPDATE [tmpManifest] SET [BOX] = '" & sUPC & "' WHERE [ID] = " & sID
CurrentDb.Execute SQL
End If
rs.MoveNext
Loop
End If