|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
老师们好,自己写的代码,发现一个问题但我不会解决,拜托了:
access 数据赋值给 arr,arr赋值给listbox,但listbox只显示数组的第一行,其他航不显示,拜托指教。谢谢
(最后两句搞不定的代码已经标红,谢谢)
Dim Stpath, strSQL As String
Dim arr, Arr3
Dim t As String
Dim RST As Object, i%, n%
Dim cnn As Object, SQL$, rs As Object ', i%, n%
mybook = ThisWorkbook.Name
mypath = ThisWorkbook.Path
mysht = ActiveSheet.Name
kigyoumei = "Finance_DB" '''■■■路径名 需要修改
documei = "Finance_DB" '''■■■数据库名 需要修改
Tabmei1 = "Parts_list" '''■■■数据表名 需要修改
t = 入库界面.TextBox1.Value
Set myCat = CreateObject("ADOX.Catalog")
Set cnn = CreateObject("Adodb.Connection")
Set RST = CreateObject("Adodb.Recordset")
Set rs = CreateObject("Adodb.Recordset")
'''''''''↓↓↓↓↓↓确认数据库是否存在↓↓↓↓↓↓'''''''''
myData = mypath & "\database\" & kigyoumei & "\" & documei & ".mdb" '设置login数据库名称(包括完整路径)
If Dir(myData) = "" Then
MsgBox myData & Chr(13) & " 文件丢失或不存在!" & Chr(13) & "请关闭系统后重新进入!密码系统会自动初始化!", 48, "错误"
Exit Sub
End If
cnn = "Provider=Microsoft.Ace.OLEDB.12.0;" & "Data Source=" & myData '建立与建数据库的连接字符串
cnn.Open "provider=Microsoft.ACE.OLEDB.12.0" & ";Data Source =" & myData & ";Persist Security Info=False;Jet OLEDB:Database Password=123"
''''''''''''''''''''''''''''判断是否有数据满足条件,如果没有满足条件的数据,就不往下走了
SQL = "Select 零部件ID from " & Tabmei1 & " WHERE 零部件ID LIKE '%" & t & "%'" '正确
rs.Open SQL, cnn
Do While Not rs.EOF
kosuu = kosuu + 1 '遍历计算数据库中一共有多少条数据
rs.MoveNext
Loop
If kosuu = 0 Then
'MsgBox "", 16, "错误"
入库界面.ListBox1.Visible = False
cnn.Close
Set RST = Nothing
Set cnn = Nothing
Set AdoRe = Nothing
Exit Sub
Else
Set AdoRe = cnn.Execute(SQL)
Arr3 = AdoRe.GetRows '取得全部
入库界面.ListBox1.List = Arr3
cnn.Close
Set RST = Nothing
Set cnn = Nothing
Set AdoRe = Nothing
End If
|
|