Try this:
Function CountFields(MyTable As String) As Integer
'*******************************************
'Name: CountFields (Function)
'Purpose: Returns the number of fields in table
'Inputs: From debug window:
' ? countfields("tblProducts")
'Returns: 6
'*******************************************
Dim db As DATABASE, td As TableDef, tName As String
Set db = CurrentDb
tName = MyTable
On Error Resume Next
Set td = db.TableDefs(tName)
If Not Err = 3265 Then 'table not found
CountFields = td.Fields.Count
End If
db.Close
Set db = Nothing
End Function