我有一个包含多个列表框的表单,我想知道如何将列表框中的项目加载到我的访问数据库中。
dim db as dao.database
dim rs as dao.recordset
dim strsql as string
dim item as variant
set db = currentdb()
strsql = "SELECT * FROM TBL WHERE ID = '"& a & "'"
set rs = db.openrecordset(strsql)
for i = 0 to me.lst1.listcount -1)
'"stuck here or I may be using the wrong code..."
next
欢迎任何帮助...
如果我没记错的话,可以通过以下方式解决您的问题:
Sub Sample()
Dim ctl as Control
Dim idx As Long
Dim db as Database
Dim rec as Recordset
Set db = CurrentDB
Set rec = db.OpenRecordset("Select * from MyTable")
'Find each listbox control on the form, and get its contents
For Each ctl In me.Controls
If ctl.ControlType = acListBox Then
'If it's a listbox, write the contents to a table
For idx = 0 To ctl.ListCount - 1
rec.AddNew
rec("MyDataField") = ctl.ItemData(idx)
rec.Update
Next
End If
Next
End Sub
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句