VBA: Getting list of TableName/FieldName

VAer-4038 771 Reputation points
2021-04-15T19:57:24.903+00:00

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]  

88382-tables.jpg

Developer technologies Visual Basic for Applications
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Tom van Stiphout 1,861 Reputation points MVP
    2021-04-17T18:25:14.317+00:00

    There are a couple of ways. Here is one:
    http://vb-helper.com/howto_ado_list_tables_fields.html

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.