Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Forms Programming / December 2005

Tip: Looking for answers? Try searching our database.

Creating New Field in Backend Table Problems.

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Gibson - 05 Dec 2005 18:45 GMT
   I am simply trying to add a field to an existing backend table using the
following code. When I get to the last line to Append idx I receive an error
message "Invalid field definition "Field1 in definition of Index or
relationship.  I think I am making this more difficult than it should be.
Can anybody see what I am doing wrong?  Thank you.

   Set wrkJet = CreateWorkspace("", "admin", "", dbUseJet)
   Set Db = wrkJet.OpenDatabase("C:\Backend.MDB", True)

   Set tdf = Db.TableDefs("tbl1")
   Set idx = tdf.CreateIndex("Field1")
   With idx
       .Fields.Append .CreateField("Field1", dbText, 20)
   End With
   tdf.Indexes.Append idx
Marshall Barton - 05 Dec 2005 19:57 GMT
>    I am simply trying to add a field to an existing backend table using the
>following code. When I get to the last line to Append idx I receive an error
[quoted text clipped - 11 lines]
>    End With
>    tdf.Indexes.Append idx

Assuming the table really has a field named field1, the only
thing obvious that strikes me is that the field type and
size arguments are not used when creating a field for an
index.

If that doesn't get past the problem, try creating the field
object as a separate step??

Signature

Marsh
MVP [MS Access]

George Nicholson - 05 Dec 2005 20:19 GMT
Creating an index doesn't create the field. You need to use tdf.CreateField
and then append the field before you can create (or, more accurately,
Append) an index based on it. Otherwise you're trying to append an index on
a field that doesn't exist.

HTH,
Signature

George Nicholson

Remove 'Junk' from return address.

>    I am simply trying to add a field to an existing backend table using
> the following code. When I get to the last line to Append idx I receive an
[quoted text clipped - 11 lines]
>    End With
>    tdf.Indexes.Append idx
Gibson - 05 Dec 2005 20:55 GMT
Thanks guys for the help. You were both right.  I was trying to create the
field so it wasn't in the table. Once I change to .CreateField everything
worked fine.  Thanks again for the help.

> Creating an index doesn't create the field. You need to use
> tdf.CreateField and then append the field before you can create (or, more
[quoted text clipped - 17 lines]
>>    End With
>>    tdf.Indexes.Append idx
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.