• Skip to main content
  • Skip to primary sidebar

Ryan McCormick

Get Column Names From Access Database Table with VBA

August 11, 2017 by Ryan Leave a Comment

It has been a long time since I have added a VBA post, so here is something that I had to quickly put together for a little project that I am working on this evening.

I have a really large table with a bunch of fieldnames that I need to query through to make some sample data for another project.

I thought that it would be easiest to quickly grab all of the field names from my target table so I can filter out only the ones I need and not manually type a bunch of field names.

I am sure there are other trivial ways of doing this, but since you found my post, you are probably looking to do what I am doing here.

Get Column Names from Access Recordset with VBA

Sub getFieldNamesFromTable(targetTable As String)
    Dim db As DAO.Database
    Dim rs As DAO.Recordset
    Dim strSQL As String
    
    Set db = CurrentDb
    
    strSQL = "SELECT TOP 1 * FROM " & targetTable
    
    Set rs = db.OpenRecordset(strSQL)
    
    For Each fName In rs.Fields
        Debug.Print fName.Name
    Next fName
    
    'Do While Not rs.EOF
    
    'Loop
    
    db.Close
    Set db = Nothing
    Set rs = Nothing
End Sub

And then to use this method, set up another sub in a module or wherever

Sub tableNamesRunner() 
	getFieldNamesFromTable ("MyAccessDBTableName")
End Sub

Filed Under: Microsoft Access Tagged With: access, get column names, vba

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

Recent Posts

  • Force Quit Kill all Chrome Windows MacOS
  • SOLVED: Angular 6 CLI Karma Stuck in Single Run | Karma Stops Running
  • How to Manually Install Java 8 on Ubuntu 18.04 LTS
  • Remove VirtualBox from Ubuntu 16.04 Xenial
  • Clear all Node Modules Folders Recursively Mac/Linux

Recent Comments

  1. KKV on Webstorm adding spaces between imports and braces | JavaScript and TypeScript
  2. jusopi on Clear all Node Modules Folders Recursively Mac/Linux
  3. Qaisar Irfan on Clear all Node Modules Folders Recursively Mac/Linux
  4. mustafa on Remove VirtualBox from Ubuntu 16.04 Xenial
  5. Pourya on How to Manually Install Java 8 on Ubuntu 18.04 LTS

Copyright © 2025 · Magazine Pro on Genesis Framework · WordPress · Log in