Before the experts ask why I would want to add fields via VBA, I am not building a typical database. I am importing large amounts of data into Access, having Access manipulate the data via queries and such, and exporting out. I use Access for the same steps pretty much everytime.
(Bare with me - I don't have access to my database right now)
My issue is that I am getting an error message in my code on the 2nd "add field to table" section of code. The error is 3265 Item not found in this collection.
I used code similar to this after I ran a make table query using db.execute "myquery" method:
That code works fine, but I run another make table query and run the same type of code to add a field as I previously did. The error stops on
I figure I have to empty tdf but i tried setting tdf = nothing but it didnt help. Do i have to db.close and db = nothing too???
What am I missing? Thanks in advance!
(Bare with me - I don't have access to my database right now)
My issue is that I am getting an error message in my code on the 2nd "add field to table" section of code. The error is 3265 Item not found in this collection.
I used code similar to this after I ran a make table query using db.execute "myquery" method:
Code:
Dim db As DAO.Database
Dim tdf As DAO.TableDef
Dim fld As DAO.Field
Set db = CurrentDb()
Set tdf = db.TableDefs("MYtable")
tdf.Fields.Append tdf.CreateField("MYfield", dbText, 30)
Code:
Set tdf=db.TableDefs("MyOtherTable")
What am I missing? Thanks in advance!