Hi Pascal,
I changes the code a bit - I tested it and works fine
Notes: It's not a good idea to name a field Month or Year as these are reserved word used for function in Access (e.g. Year(datefield))
You have to set the Attributes of the field before appending it.
I just made them all text fields. If they have to be Number, Currency, date fields just change the dbtext to dbLong or DbCurrency etc.
Function VeldenToevoegen()
Dim db As DAO.Database
Dim td As TableDef
Dim Veld As Field
Set db = CurrentDb
Set td = db.TableDefs("Gegevens")
For Each Veld In td.Fields ' not quite sure why this?
If Veld.Name = "Year" Or Veld.Name = "Month" Or Veld.Name = "Branch" Or Veld.Name = "Assignment" Then
Set Veld = Nothing
Exit Function
End If
Next
'***********
Set td = db.TableDefs("Gegevens")
Set Veld = td.CreateField("Jaartal", dbText, 50) 'it's not a good idea to name a field Year or Month - these are reserved and names of functions in access!!
Veld.OrdinalPosition = 1
Veld.AllowZeroLength = True ' you don't have to set these properties - they take the standard if you don't
Veld.Required = False
td.Fields.Append Veld
Set Veld = td.CreateField("Maandtal", dbText, 50) 'it's not a good idea to name a field Year or Month - these are reserved and names of functions in access!!
Veld.OrdinalPosition = 2
Veld.AllowZeroLength = True
Veld.Required = False
td.Fields.Append Veld
Set Veld = td.CreateField("Bedrijf", dbText, 50)
Veld.OrdinalPosition = 3
Veld.AllowZeroLength = True
Veld.Required = False
td.Fields.Append Veld
Set Veld = td.CreateField("Toekenning", dbText, 50)
Veld.OrdinalPosition = 4
Veld.AllowZeroLength = True
Veld.Required = False
td.Fields.Append Veld
td.Fields.Refresh
'**************************
Set td = Nothing
Set db = Nothing
End Function