Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
Currentdb.TableDefs("any given").Fields.Count
It would help if you said I have a table named "tblEmployees" or "tblImport" that I need code to ...Lost500 said:i have in any given table
Option Compare Database
Sub fieldcounter()
Dim fieldcount As String
Set fieldcount = CurrentDB.TableDefs("mytablename").Fields.Count
MsgBox fieldcount
End Sub
Sub fieldcounter()
Dim intFieldCount As Integer
intFieldCount = CurrentDB.TableDefs("mytablename").Fields.Count
MsgBox intFieldCount
End Sub
Option Compare Database
Sub Chris()
Dim CurrentDB As Database
Dim ExclFile As Excel.Workbook
Dim Table As Recordset
Dim i As Integer
Set ExclFile = GetObject("C:\Documents and Settings\cpope2\Desktop\Chris ExclFile.xlsx")
Set CurrentDB = DBEngine.Workspaces(0).Databases(0)
Set Table = CurrentDB.OpenRecordset("tablename", dbOpenTable, dbConsistent)
Table.Index = "indexable field name"
For i = 2 To 96
Table.Seek "=", ExclFile.Sheets(1).Cells(i, 1)
If Table.NoMatch Then
MsgBox ExclFile.Sheets(1).Cells(i, 1) & " " & ExclFile.Sheets(1).Cells(i, 2) & " " & i
Else
Table.Edit
Table("fieldname") = ExclFile.Sheets(1).Cells(i, 13)
Table.Update
End If
Next
To the be sure [blue]Microsoft DAO x.x Object Library[/blue] is key here. The [blue]Count[/blue] property won't work without it! You've completely skipped over this.dhookom said:[blue]The code uses the [purple]DAO object library[/purple]. [green]You may need to set a reference[/green] to the Microsoft DAO xxx object library while in a module.[/blue]
[blue]Debug.Print CurrentDb.TableDefs("[purple][B][I]YourTableName[/I][/B][/purple]").Fields.Count[/blue]
? CurrentDb.TableDefs("[i][b]YourTableName[/b][/i]").Fields.Count