1,507 questions
There are a couple of ways. Here is one:
http://vb-helper.com/howto_ado_list_tables_fields.html
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Is it possible to write VBA code to get table name and field name from database?
For example, if I have Sybase database abc, and I would like to list all tables and fields in sheet Output, something like below screenshot.
Is it possible? If yes, how to complete my code?
Thanks.
![Private Sub CommandButtonGettingTableAndField_Click()
Dim Cn As Object
Dim WB As Workbook
Dim WS As Worksheet
Username = TextBoxUsername.Value
Password = TextBoxPassword.Value
ConnectionString = "Driver={Adaptive Server Enterprise};server=xyz;port=11111;db=abc;uid=" & Username & ";pwd=" & Password & ";"
Set Cn = CreateObject("ADODB.Connection")
Cn.Open ConnectionString
Set WB = Workbooks.Add
WB.Sheets(1).Name = "Output"
For Each WS In WB.Worksheets
If WS.Name <> "Output" Then
Application.DisplayAlerts = False
WS.Delete
Application.DisplayAlerts = True
End If
Next WS
'How to get table names and field names from database abc?
Set Cn = Nothing
End Sub][1]
There are a couple of ways. Here is one:
http://vb-helper.com/howto_ado_list_tables_fields.html