MS Access查找和更新另一个字段

时间:2018-08-10 14:41:28

标签: vba ms-access access-vba

我从如下所示的条形码扫描仪接收数据。我需要在ID字段中填充BoxID(类型=整数)。

enter image description here

这是理想的结果-ID唯一标识该框: enter image description here

1 个答案:

答案 0 :(得分:1)

假设数据一致,请考虑:

Sub SetBoxID()
Dim rs As DAO.Recordset, intID As Integer
Set rs = CurrentDb.OpenRecordset("SELECT * FROM Table1 ORDER BY ID")
While Not rs.EOF
    If rs!Type = "Box" Then 
       intID = rs!ID
    ElseIf rs!Type = "Desp" Then
        rs.Edit
        rs!BoxID = intID
        rs.Update
    End If
    rs.MoveNext
Wend
End Sub