Thanks very much for that - works perfectly.
I've also managed to get the new field to be at the top of the field 
list. I added:
tdfField.OrdinalPosition = position
after the first line: Set tdfField = .CreateField(fieldname, dbLong)
Thanks again
Jane

--- In [email protected], "Duane Hennessy" 
<[EMAIL PROTECTED]> wrote:
>
> 
> Jane,
>  Here's an answer for the Autonumber field part of your question. 
First add the pink line below, between creating your field and 
appending it to the table. It's self-explanatory :)
> 
> Set tdfField = .CreateField(fieldname, dbLong)
> tdfField.Attributes = dbAutoIncrField
> .Fields.Append tdfField
> 
> If you want it to be a Primary Key aswell add the following code 
directly after the above code, don't change anything as we need to 
append the field in the above code before creating the same field 
from the index (I don't know why!) 8-|
> 
> Set idx = .CreateIndex("primary_key")
> idx.Primary = True 'Sets the primary key part of the index
> idx.Name = "primary_key"
> Set tdfField = idx.CreateField(fieldname, dbLong)
> idx.Fields.Append tdfField
> .Indexes.Append idx
> 
> That should fix your autonumber/primary key problem :D
> 
> Cómo es eso?
> 
> Duane Hennessy.
> Bandicoot Software 
> Tropical Queensland, Australia 
> (ABN: 33 682 969 957) 
> 
> Want Increased Productivity? 
> http://www.bandicootsoftware.com.au 
> 
> 
> --- In [email protected], "vjcross2004" 
<[EMAIL PROTECTED]> wrote:
> >
> > I can add a new 'long' field to an existing table a linked back 
end 
> > database, but how can I add a new AutoNum field?
> > 
> > Also is there a way to put it at the top of the field list? I 
have 
> > been playing with the OrdinalPosition property but can't get it 
to 
> > work right?
> > 
> > Thanks
> > Jane
> > 
> > Here's a cut down version of what I have so far:
> > 
> > Dim dbsUpdate As Database, wrkDefault As Workspace
> > Dim tdfUpdate As TableDef, tdfField As Field
> > 
> > linkpath="Z:\Databases\OrdersData.mdb"
> > tableName="Rejects"
> > fieldname="RejectID"
> > 
> > Set wrkDefault = DBEngine.Workspaces(0)
> > Set dbsUpdate = wrkDefault.OpenDatabase(linkpath, True)
> > Set tdfUpdate = dbsUpdate.TableDefs(TableName)
> > With tdfUpdate
> > fieldname="RejectID"
> > Set tdfField = .CreateField(fieldname, dbLong)
> > .Fields.Append tdfField
> > End With
> >
>








Please zip all files prior to uploading to Files section. 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/AccessDevelopers/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 


Reply via email to