Count number of columns in a table

Bart2013

New member
Local time
Today, 14:38
Joined
Feb 28, 2013
Messages
9
Hi Guys,

I am importing data from Excel into 3 different tables. I want to make sure that all columns are imported so I want to count them. Does anybody know how to do that? (Or a link to an existing thread)

So not a record count, but a column count. I need a query or a msgBox that only tells me "235 columns" or so.

Thanks!
 
Thanks eblieb,

I am not very familiar with vba, so I don't know what to do with that line op code...
How do I get the number of the count in a form or query?
 
Bart2013, the code given by Moniker would be the best, but I have wrapped it in a function so that you can use that function to be called to get the Column count..
Code:
Public Function getColumnCount(strTableName As String) As Integer
[COLOR=Green]'-------------------------------------------------------------------------
'   A Function that will take in a Table Name in the current database
'   and returns the number of columns in the table.
'
'   Input   : A Normal String, that represents the name of the table
'   Output  : An integer Number, representing thr number of columns
'   Example :
'       MsgBox(getColumnCount("Transactions"))
'       123
'--------------------------------------------------------------------------[/COLOR]
On Error GoTo errHandler
    getColumnCount = CurrentDb.TableDefs(strTableName).Fields.Count
exitOnErr:
    Exit Function
errHandler:
    If Err.Number = 3265 Then
        Call MsgBox("The table name you entered :" & strTableName & _
                    ", is not found in the Current DB, please make sure you have spelled the name correctly", _
                    vbCritical, "Table not found")
        Resume exitOnErr
    Else
        Call MsgBox("Unexpected Error occured !" & _
                    "Error(" & Err.Number & ") : " & Err.Description, _
                    vbCritical, "Table not found")
        Resume exitOnErr
    End If
End Function
If you wish to use it Form, then create an unbound Text box and set its Control source as..
Code:
= getColumnCount("yourTableName")
 

Users who are viewing this thread

Back
Top Bottom