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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Access Autonumber question 2

Status
Not open for further replies.

engcon

Programmer
Jun 8, 2005
5
US
I am using the code snippet (part of program is below) and would like to make the created fileld "ID" a Primary Key and an AutoNumber field. I cannot find a way to do this in VB6. I currently have a pause in my program and go in and manually make the changes to the "ID" field after this part of the program has completed the I click OK and run the rest of the program to populate the table.

Any help would be appreciated.

Thanks


Set dbsNew = OpenDatabase(App.Path & "\New-db1.mdb")

Set tdfNew = dbsNew.CreateTableDef("REFORMAT")

With tdfNew
.Fields.Append .CreateField("ID", dbLong)
.Fields.Append .CreateField("Owner", dbText, 40)
Set dbindex = .CreateIndex("Owner" & "index")
Set indexfield = dbindex.CreateField("Owner")
dbindex.Fields.Append indexfield
.Indexes.Append dbindex
.Fields.Append .CreateField("Add1", dbText, 25)
.Fields.Append .CreateField("Add2", dbText, 25)
<><><><><><><><><><><><><><><> More of same in here <<<<<
dbsNew.TableDefs.Append tdfNew
End With
dbsNew.Close
 
Add:

.Fields("ID").Properties("Attributes")=17

Immediately after:

.Fields.Append .CreateField("ID", dbLong)

Ed Metcalfe.

Please do not feed the trolls.....
 
Thanks for the info. I will give it a try. By the way, where can I find a list of the attributes.

Thanks again.

engcon
 
Ed2020

Thanks.

The addition worked great.
 
From the DAO Documentation
[tt]
Constant Description


dbAutoIncrField The field value for new records is automatically incremented to a unique Long integer that can't be changed (in a Microsoft Jet workspace, supported only for Microsoft Jet database(.mdb) tables).

dbDescending The field is sorted in descending (Z to A or 100 to 0) order; this option applies only to a Field object in a Fields collection of an Index object. If you omit this constant, the field is sorted in ascending (A to Z or 0 to 100) order. This is the default value for Index and TableDef fields (Microsoft Jet workspaces only).

dbFixedField The field size is fixed (default for Numeric fields).

dbHyperlinkField The field contains hyperlink information (Memo fields only).

dbSystemField The field stores replication information for replicas; you can't delete this type of field (Microsoft Jet workspaces only).

dbUpdatableField The field value can be changed.

dbVariableField The field size is variable (Text fields only).
[/tt]

"Attributes" and "Properties" are however, different things. The above are valid settings for "Field.Attributes"
 
Golom,

Thanks for the info. I must have overlooked it in my frantic searching for that sort of data.

Thanks a buch. This Forum really is great.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top