Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to Create AutoNumber Field progmatically...

Status
Not open for further replies.

egapogi

Programmer
Feb 4, 2002
60
PH
Hey folks...

I can create a table progmatically add fields to it...

I can also open an existing table and add new field(s) on it...

Now, I want to add a field which is autonumber to one of my existing table using VBA.

Autonumber fields are Long Integer. If I create field(s) progmatically, I can specify type as 4; or dblonginteger..
but how can i say that the field should be an autonumber field?..

I hope I am clear.. sorry if I am confusing you...

thanks..
egapogi
 
Hi,


Use Attributes, and use constant dbAutoIncrField.

Sorry i never try, because i never use the Automatic field, but this exemple from the help in the Microsoft Access i hope this is what you search.

Sorry for the description is in french, i use the french version of the Access 97.

Sub AttributesX()

Dim dbsNorthwind As Database
Dim fldLoop As Field
Dim relLoop As Relation
Dim tdfloop As TableDef

Set dbsNorthwind = OpenDatabase("Comptoir.mdb")

With dbsNorthwind

' Affiche la propriété Attributes des champs
' d'un objet TableDef.
Debug.Print "Attributs des champs dans la table " & _
.TableDefs(0).Name & " :"
For Each fldLoop In .TableDefs(0).Fields

Debug.Print " " & fldLoop.Name & " = " & _
fldLoop.Attributes
Next fldLoop

' Affiche la propriété Attributes des objets
' Relation
' de la base de données Comptoir.
Debug.Print "Attributs des relations dans " & _
.Name & ":"
For Each relLoop In .Relations
Debug.Print " " & relLoop.Name & " = " & _
relLoop.Attributes
Next relLoop

' Affiche la propriété Attributes des tables
' de la base de données Comptoir.
Debug.Print "Attributs des tables " & .Name & ":"
For Each tdfloop In .TableDefs
Debug.Print " " & tdfloop.Name & " = " & _
tdfloop.Attributes
Next tdfloop

.Close
End With

End Sub

regards,

Eric Poirier
 
Hi Eric Poirier,

that works great....

thanks a lot,
egapogi
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top