请问在使用VB建立mdb数据库时,如何将字段属性设为自动编号?

社会网编2023-03-11 12:461830

  用create table aaa(field1 AutoIncrement)可实现你想要的功能

代码如下:

'菜单“工程”-->"引用"-->"Microsoft ActiveX Data Objects 2。5 Library"

Dim Con As Connection

Dim Rs As Recordset

Dim strCn as string

strCn= "Provider=Microsoft。

  Jet。OLEDB。4。0;Data Source=你新建库名称。mdb;Persist Security Info=False"

Set Con = New Connection

Con。Open strCn

strCn = "create table aaa(field1 AutoIncrement,field2 text(10))" '建立aaa表,字段filed1为自动编号型,字段field2为10位字符型

Con。

  Execute strCn

con。close

set con=nothing

如用

Set fldMethod = tldMthdDamage。CreateField("DamageID", ?????)的这种方式,可用如下方法:

Set fldMethod = tldMthdDamage。

  CreateField()

With fldMethod

。Name = "Field1"

。Type = dbLong

。Size = 6

。Attributes = dbAutoIncrField

End With

评论区