Can't add new field after deleting fields

2019-08-09 12:38发布

I am using MS Access 2010.

Situation:

Table reach 225 fields

Delete one field (so there is 224 fields "visible" in the table)

Add new field

Get error 3109 "Too many fields defined."

I add and delete fields with VBA.

Add:

Dim dbs as Database
Set dbs = CurrentDb()
queryAlter = "ALTER TABLE [Table] ADD [" & [field] & "] Varchar(255)"
dbs.Execute queryAlter, dbFailOnError
dbs.Close

I add a field with a query because its easier for me

Delete:

Dim dbs as Database
Dim field as Field
Set dbs = CurrentDb()
    Do While dbs.TableDefs([Table]).Fields.count > 3
        Set field = dbs.TableDefs([Table]).Fields(3)
        dbs.TableDefs([Table]).Fields.Delete field.name
    Loop
dbs.Close

I want the first 3 fields to be stayed in the table I don't use a query because this was faster for me. (I thought)

1条回答
▲ chillily
2楼-- · 2019-08-09 13:06

In your delete code, before closing database do method TableDefs.Refresh

查看更多
登录 后发表回答