Advertisement
Guest User

Untitled

a guest
Dec 15th, 2018
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1.  
  2. Private Sub CommandButton1_Click()
  3. Dim cn As ADODB.Connection
  4. Dim rst As ADODB.Recordset
  5.  
  6. dbFileName = Application.GetOpenFilename _
  7. ("Access Files (*.accdb), *.accdb")
  8. If dbFileName = False Then Exit Sub
  9.  
  10. Set cn = New ADODB.Connection
  11. cn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;" & _
  12. "Data Source=" & dbFileName & ";Mode=Read"
  13. On Error Resume Next
  14. cn.Open
  15.  
  16. If cn.State = 1 Then
  17. ListBox1.Clear
  18. ListBox1.ColumnWidths = "100,200"
  19. Set rst = New ADODB.Recordset
  20. Set rst = cn.OpenSchema(adSchemaTables)
  21. rst.MoveFirst
  22. Do While Not rst.EOF
  23. ListBox1.AddItem
  24. ListBox1.List(ListBox1.ListCount - 1, 0) = rst.Fields.Item("TABLE_TYPE")
  25. ListBox1.List(ListBox1.ListCount - 1, 1) = rst.Fields.Item("TABLE_NAME")
  26. rst.MoveNext
  27. Loop
  28. rst.Close
  29. Set rst = Nothing
  30. Else
  31. MsgBox "Íå óäàåòñÿ ïîäêëþ÷èòüñÿ ê áàçå" & vbCr & dbFileName
  32. dbFileName = False
  33. End If
  34. cn.Close
  35. Set cn = Nothing
  36. Label1.Caption = dbFileName
  37.  
  38. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement