Error in Access: Too many fields defined

After installing my application in offices, "run time error '3190' - Too many fields defined" occurs when I tried to create an addtional field in one of my tables in MS Access at run time. I clicked on Help button and it says I exceeded the 255 field limit. My table has only 15 fields and an average of 10,000 records.


Private Sub Text8_KeyPress(KeyAscii As Integer)
Dim ws As Workspace
Dim db As Database
Dim CheckTicket, TempRec As Recordset
Dim td As TableDef
Dim fld As Field

    Select Case KeyAscii
        Case vbKeyReturn, vbKeyTab
            StatusBar1.Panels(1).Text = "Please wait..."
            Set ws = DBEngine.Workspaces(0)
            Set db = ws.OpenDatabase("c:\btfb\btfb.mdb")
            Set td = db.TableDefs("trnxfile")
            Set fld = td.CreateField("temp", dbInteger)
            td.Fields.Append fld <-The error occurs here

meng_97Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

tirupur_selvaCommented:
Hi,
   Do you get the error message the very first time or after a fewtimes the keypress event is fired?.
0
anthonycCommented:
on the second keypress, you are attempting to add a second field called TEMP.... You can't name a field the same thing twice!
0
tirupur_selvaCommented:
Instead of
 Dim fld as Field
try
 Dim fld as new field
& see to it that the field duplication does not occur.

or try the following:

private sub Text8_KeyPress(KeyAscii As Integer)
   Dim Ws As Workspace
   Dim Db as Database

   Set Ws = DBEngine.Workspaces(0)
   Set Db = Ws.OpenDatabase(App.path & "\dtfb.MDB")

AdNewField Db, "Purchase","PRate",DbLong

End Sub

Public Sub AdNewField(dbsDB as Database, TableName As String, FieldName As String, FieldType As Integer, Optional FieldSize As Integer, Optional ZeroLength, Optional Required, Optional Attributes)
   Dim fldField as New Field
   
   fldField.Name = FieldName
   fldField.Type = FieldType

   If Not IsMissing(FieldSize) Then fldField.Size = FieldSize
   If Not IsMissing(ZeroLength) Then fldField.AllowZeroLength = ZeroLength
   If Not IsMissing(Required) Then fldField.Required = Required
   If Not IsMissing(Attributes) Then fldField.Attributes = Attributes
   
   dbsDB.TableDefs(TableName).Fields.Append fldField

End Sub


Note:
To add a field in a database, I dont think the keypress event is a right event. Why dont you try some click event?

Regs
Selva
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.