|
菜鸟初学access,近日在编写代码的时候遇见如下问题:
原本目的是想获取数据库内表的名称,并加入到一个数组内。在测试下面代码的时候,发现循环的次数不太靠谱。数据库内只有8张空表,但循环次数为21次。恳请各位大师指点迷津,不胜感激!
- Sub updateaddRecords2007()
- Dim cnn As New ADODB.Connection
- Dim rst As New ADODB.Recordset
- Dim myPath As String
- Dim myTable As String
- Dim strTemp As String
- Dim arrFields As Variant
- Dim m
- Dim f()
- myPath = ThisWorkbook.Path & "\test1.accdb"
-
- With cnn
- .ConnectionString = "Provider=Microsoft.Ace.OLEDB.12.0;Data Source=" & myPath '连接数据库
- .Open
- End With
- Set rst = cnn.OpenSchema(adSchemaTables)
-
-
- m = 1
- Do Until rst.EOF
- If rst!table_type = "TABLE" Then
- ReDim Preserve f(m)
- f(m) = rst!table_name
- End If
- rst.MoveNext
- m = m + 1
- Loop
-
- rst.Close
- cnn.Close
- Set rs = Nothing
- Set cnn = Nothing
- End Sub
复制代码
test1.zip
(24.64 KB, 下载次数: 2)
|
|