By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,573 Members | 3,017 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,573 IT Pros & Developers. It's quick & easy.

How to make a counter field in Access 2.0 using something like Set MyField = MyTableDef.CreateField("Segment", DB_LONG)

P: n/a
MLH
I would like to modify the following Access Basic code in Access 2.0
app so the [Segment] field would an automatic counter-type field.

Dim DefaultWorkspace As WorkSpace, CurrentDatabase As Database
Dim MyTableDef As TableDef
Dim MyField As Field
Set DefaultWorkspace = DBEngine.Workspaces(0)
Set CurrentDatabase = DefaultWorkspace.Databases(0)
Set MyTableDef = CurrentDatabase.CreateTableDef("tblTempTable")
Set MyField = MyTableDef.CreateField("Segment", DB_LONG)
MyTableDef.Fields.Append MyField
Set MyField = MyTableDef.CreateField("SegmentText", DB_MEMO)
MyTableDef.Fields.Append MyField
CurrentDatabase.TableDefs.Append MyTableDef

Can anyone tell me how to modify the above code so [Segment] will
be a counter field upon creation?
Nov 13 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
With Access 97, you'd use

Set MyTableDef = CurrentDatabase.CreateTableDef("tblTempTable")
Set MyField = MyTableDef.CreateField("Segment", dbLong)
MyField.Attributes = MyField.Attributes + dbAutoIncrField
MyTableDef.Fields.Append MyField

Unfortunately, I don't have Access 2 handy, so I can't check what the
equivalent to dbAutoIncrField would be in Access 2.0. dbAutoIncrField is
equal to 16. See if that works.

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)

"MLH" <CR**@NorthState.net> wrote in message
news:ql********************************@4ax.com...
I would like to modify the following Access Basic code in Access 2.0
app so the [Segment] field would an automatic counter-type field.

Dim DefaultWorkspace As WorkSpace, CurrentDatabase As Database
Dim MyTableDef As TableDef
Dim MyField As Field
Set DefaultWorkspace = DBEngine.Workspaces(0)
Set CurrentDatabase = DefaultWorkspace.Databases(0)
Set MyTableDef = CurrentDatabase.CreateTableDef("tblTempTable")
Set MyField = MyTableDef.CreateField("Segment", DB_LONG)
MyTableDef.Fields.Append MyField
Set MyField = MyTableDef.CreateField("SegmentText", DB_MEMO)
MyTableDef.Fields.Append MyField
CurrentDatabase.TableDefs.Append MyTableDef

Can anyone tell me how to modify the above code so [Segment] will
be a counter field upon creation?

Nov 13 '05 #2

P: n/a
MLH
Hey, thanks much for the lead. A minor adjustment for Access 2.0
which uses DB_AUTOINCRFIELD as opposed to dbAutoIncrField.
I owe you one.

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

On Sat, 9 Oct 2004 19:50:20 -0400, "Douglas J. Steele"
<NOSPAM_djsteele@NOSPAM_canada.com> wrote:
With Access 97, you'd use

Set MyTableDef = CurrentDatabase.CreateTableDef("tblTempTable")
Set MyField = MyTableDef.CreateField("Segment", dbLong)
MyField.Attributes = MyField.Attributes + dbAutoIncrField
MyTableDef.Fields.Append MyField

Unfortunately, I don't have Access 2 handy, so I can't check what the
equivalent to dbAutoIncrField would be in Access 2.0. dbAutoIncrField is
equal to 16. See if that works.


Nov 13 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.