С этим кодом не получилось - пишет, что oTable=Empty
Private Sub Form_Load()
' Enumerate tables in catalog
For Each oTable In oCatalog.Tables
' Filter on user tables only
If oTable.Type = "TABLE" Then
ctrlListBox.AddItem Item:=oTable.Name
'MsgBox "Table Name: " & oTable.Name
End If
Next
End Sub
Добавлено: Попробывал и так
Private Sub Form_Load()
On Error Resume Next
Dim MyDatabase As Database
Set MyDatabase = DBEngine.Workspaces(0).Databases(0)
' Enumerate table definitions.
If MyDatabase.TableDefs.Count > 0 Then
Dim iTable As Integer
ctrlListBox.AddItem Item:="TableDefs"
ctrlListBox.AddItem Item:="Name, DateCreated"
For iTable = 0 To MyDatabase.TableDefs.Count - 1
ctrlListBox.AddItem Item:=MyDatabase.TableDefs(iTable).Name
ctrlListBox.AddItem Item:=MyDatabase.TableDefs(iTable).DateCreated
Next iTable
End If
End Sub
Но тоже не работает... ошибку не выдаёт. просто не показывает список таблиц...
вот форма в конструкторе:
http://img710.imageshack.us/img710/9463/93471194.jpg а здесь просто в режиме формы:
http://img229.imageshack.us/img229/1013/62430617.jpg Я же вроде бы всё правильно сделал?)
Добавлено: Попробывал ещё вот так
Public cnnACC As ADODB.Connection 'Access Connection
Public adoCat As ADOX.Catalog 'Catalog
Public adoTbl As ADOX.Table 'Table
Public Sub Form_Load()
Dim strDB, strConn As String
'Set New connection
Set cnnACC = New ADODB.Connection
'String Database Path
Set strDB = CurrentDb()
'String Connection with Database path String
strConn = "Provider=Microsoft.Jet.OLEDB.4.0; " & _
"Data Source=" & strDB & ";"
' Open the connection
cnnACC.Open strConn
'Set new ADOX CAtalog
Set adoCat = New ADOX.Catalog
'Allow active connection to the opened connection to enable use of the catalog
adoCat.ActiveConnection = cnnACC
'Clear the Userform list box to refresh tables
List19.Clear
For Each adoTbl In adoCat.Tables
Select Case adoTbl.Name
Case "MSysAccessObjects", "MSysAccessXML", "MSysACEs"
'Ignore System tables listed above
Case "MSysObjects", "MSysQueries", "MSysRelationships"
'Ignore System tables listed above
Case Else
'Add Non-system table names
List19.AddItem adoTbl.Name
End Select
Next adoTbl
'Clear Memory
Set cnnACC = Nothing: Set adoCat = Nothing
End Sub
Тоже не пашет...