Tuesday, September 9, 2008

Getting the column and row count of all queries in an MS Access database via VBA module

For Each tempQuery In CurrentDb.QueryDefs
'for each query in the database

If InStr(tempQuery.Name, "TMP") = 0 Then
'avoid picking up temp queries,
'via substring check

ColumnCount = CurrentDb.QueryDefs(tempQuery.Name).Fields.Count
'get the column count for the query

RowCount = DCount("*", tempQuery.Name)
'get the row count for the query

MsgBox(tempQuery.Name + vbTab + _
Str(ColumnCount) + vbTab + Str(RowCount))

End If

Next

No comments: