• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 642
  • Last Modified:

SQL Server field names VBA

I have a SQL server 2008 database with a table called Invoices.

Using Access 2007 VBA code, how do I get all the field names from the table Invoices.
0
Idarac
Asked:
Idarac
1 Solution
 
Computer EggheadCommented:
Link your SQL Server table into your Access database, and create a module that you can run with the code shown here:  TableInfo() function
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
if you can already query the table (ADODB), you simply can run this query
SELECT * FROM Invoices WHERE 1 = 0

Open in new window

, and loop on the recordset's FIELDS collection.
0
 
IrogSintaCommented:
Here's some code you could play with:
    Dim rs As Recordset
    Dim fld As Field
    
    Set rs = CurrentDb.OpenRecordset("Select * From TABLENAME Where FALSE")
    For Each fld In rs.Fields
        Debug.Print fld.Name
    Next
    rs.Close
    Set rs = Nothing

Open in new window

Ron
0
 
IdaracAuthor Commented:
Works great ode was pretty close. Just had to play with it a bit
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now