Marshall
The reason I'm trying to do this is I want to create a table in code instead
of from the design view with the correct properties.
If i use the CreateTable first and then call the code below, I receive:
"There are several tables with that name. Please specify owner in the format
'owner.table'."Set NewTable = MyDatabase.TableDefs("TabNewWiring2")"
statement.
If I take an existing table and remove all the fields except for 1, run the
following it works. If I create a table from scratch in the design view with
1 field and run the same thing, I recieve "Item not found in this collection"
on the "Set NewTable = MyDatabase.TableDefs("TabNewWiring2") statement. What
is the reason for this?
Function CreateOthers()
Dim MyDatabase As Database, NewTable As TableDef
Dim fldTemp As Field
On Error GoTo CreateOtherdef
Set MyDatabase = DBEngine.Workspaces(0).Databases(0)
Set NewTable = MyDatabase.TableDefs("TabNewWiring2")
' Create a new Field object and append it to the Fields
' collection of the Employees table.
Set fldTemp = NewTable.CreateField("Field2", dbText, 10)
fldTemp.AllowZeroLength = True
NewTable.Fields.Append fldTemp
DoCmd.SetWarnings True
Exit Function
CreateOtherdef:
Debug.Print Error$
Stop
End Function
"Marshall Barton" wrote:
> jbruen wrote:
> >I add the following statment after the CreateTabledef1 label and received
> >the same error: Set tdfEmployees = MyDatabase.CreateTabledef("Employees").
> >
> >Do I have to create the table the original way using ".Fields.Append
> >.CreateField("RefNO", dbText)", then use the tabledefs statement to change
> >the attributes? If so I guess I can't do this at the same time, it has to be
> >a 2 step process.
> >
> >This is really a onetime process to create the table for a conversion. That
> >is why I have to delete in there to remove the table before I do create it.
> >If I have a lot of fields instead of creating them manually, I would rather
> >do something like this if possible.
>
>
> Since you deleted the TableDef, then yes,when you
> (re)create the TableDef, you have to r(e)create the fields,
> properties, indexes, etc.
>
> If this is a "one" time operation, how about creating the
> table manually using the table design window? When you want
> to test you can Copy/Paste the "template" table (in the DB
> window) to make a fresh version of the working table.
>
> --
> Marsh
> MVP [MS Access]
>
|