Windows 10
Access 2013
Sub test1()
Dim sTblName As String
Dim lCol As Long
sTblName = "テーブル名"
lCol = lFieldCount(sTblName)
Debug.Print sTblName & "_Count:" & lCol
End Sub
Public Function lFieldCount(sTblName As String) As Long
'対象テーブルの フィールド数を取得する。
'ツール→参照設定→ Microsoft ActiveX Data Objects *.* Library にチェック
Dim cn As ADODB.Connection
Dim rs As New ADODB.Recordset
Set cn = CurrentProject.Connection
'レコードセットを開く
rs.Open sTblName, cn, adOpenKeyset, adLockOptimistic
'列数を調べる
lFieldCount = rs.Fields.Count
Debug.Print lFieldCount
rs.Close
cn.Close
Set cn = Nothing
Set rs = Nothing
End Function
Access 2013
Sub test1()
Dim sTblName As String
Dim lCol As Long
sTblName = "テーブル名"
lCol = lFieldCount(sTblName)
Debug.Print sTblName & "_Count:" & lCol
End Sub
Public Function lFieldCount(sTblName As String) As Long
'対象テーブルの フィールド数を取得する。
'ツール→参照設定→ Microsoft ActiveX Data Objects *.* Library にチェック
Dim cn As ADODB.Connection
Dim rs As New ADODB.Recordset
Set cn = CurrentProject.Connection
'レコードセットを開く
rs.Open sTblName, cn, adOpenKeyset, adLockOptimistic
'列数を調べる
lFieldCount = rs.Fields.Count
Debug.Print lFieldCount
rs.Close
cn.Close
Set cn = Nothing
Set rs = Nothing
End Function