简体   繁体   English

MS Access VBA 更新组合框表字段

[英]MS Access VBA to update a Combobox table field

I have a table with a field with the display control set to Combo Box and I have not been able to read or write to it using an OpenRecordSet.我有一个表,其中一个字段的显示控件设置为组合框,但我无法使用 OpenRecordSet 对其进行读取或写入。 What would I have to do to modify to get these scenarios to work?我需要做些什么来修改才能使这些场景发挥作用?

Sub TryToRead()
Set db = CurrentDb
Set rs = db.OpenRecordset("tbl", dbOpenDynaset)
x = rs!FieldName '<------Combo Box Field. x shows no info.
End Sub

Sub TryToWrite()

Set db = CurrentDb
Set rs = db.OpenRecordset("tbl", dbOpenDynaset)
With rs
.AddNew
rs!FieldName = "Test Value" '<------ Results in Run-time error 64224 Application-defined or object-defined error
   .Update
End With

End Sub

I think I have what I need.我想我有我需要的东西。

Sub Testing()

Set db = CurrentDb
Set rs = db.OpenRecordset("tbl", dbOpenDynaset)
MyStr = Array("Value1", "Value2")

Do Until rs.EOF = True
    Set rs2 = rs!FieldName!Value
    rs.Edit
    For Each c In MyStr
        rs2.AddNew
        rs2!Value.Value = c
        rs2.Update
    Next c
    rs.Update
    rs.MoveNext
Loop

End Sub结束子

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM