Solved

SQL Server field names VBA

Posted on 2014-02-09
4
614 Views
Last Modified: 2014-02-09
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
Comment
Question by:Idarac
4 Comments
 
LVL 2

Expert Comment

by:Computer Egghead
ID: 39845937
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
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 39845953
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
 
LVL 29

Accepted Solution

by:
IrogSinta earned 500 total points
ID: 39845981
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
 
LVL 1

Author Closing Comment

by:Idarac
ID: 39846193
Works great ode was pretty close. Just had to play with it a bit
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Union 2 queries to a cte (temp table perhaps) 9 36
convert null in sql server 12 35
SQL multicriteria from ONE textbox 32 46
Help with DoEvents 8 30
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

825 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question