佳礼资讯网

 找回密码
 注册

ADVERTISEMENT

查看: 1090|回复: 1

<--这个 coding set auto increament要怎样的改呢?

[复制链接]
发表于 6-2-2007 11:56 AM | 显示全部楼层 |阅读模式
转贴
http://support.microsoft.com/?kbid=304418

MORE INFORMATION
To programmatically create an AutoNumber field and set the field's New Values property to Random, follow these steps: 1. Start Microsoft Access.
2. On the File menu, click New. In the New File task pane, click Blank Database. Type a path and file name for the database, and then click Create.
3. On the View menu, point to Database Objects, and then click Modules. Click New.
4. Add the Microsoft DAO 3.6 Object Library to your database's references.
5. Type the following sample code in the new module:



5. Type the following sample code in the new module: Sub CreateRandomAutonumber()
' Create database, tabledef, and field objects.
Dim db As DAO.Database
Dim td As DAO.TableDef
Dim f As DAO.Field

' Set the database object to the current database.
' Set the tabledef object to a new table named Table1.
' Set the f (field) object to a new field in Table1 named MyAutoNumber.

Set db = CurrentDb
Set td = db.CreateTableDef("Table1")
Set f = td.CreateField("MyAutoNumber")

' Set the type and auto-increment properties for the Table1 field named
' MyAutoNumber.

f.Type = dbLong
f.Attributes = dbAutoIncrField

' Append the MyAutoNumber field to Table1.
td.Fields.Append f

' Create a new text field in Table1.
Set f = td.CreateField("MyTextField")

' Set the type property for MyTextField.
f.Type = dbText

' Append the MyTextField field to Table1.
td.Fields.Append f

' Append the Table1 tabledef to the database.
db.TableDefs.Append td

' Set the default value for MyAutoNumber to a random number function.
td.Fields("MyAutoNumber").DefaultValue = "GenUniqueID()"

' Refresh the database window.
Application.RefreshDatabaseWindow

End Sub
&#160;
如果我不要random的text呢?可以吗?
回复

使用道具 举报


ADVERTISEMENT

 楼主| 发表于 6-2-2007 12:03 PM | 显示全部楼层
再转贴

http://www.tek-tips.com/viewthread.cfm?qid=1328889&page=1

这边也是

=Dmax(“[ID]”,”tablename”)+1

或者

Let’s say you want an autonumbered field by Microsoft but want some characters in front of the number like mc001, mc002, etc. Go to design view, click on the autonumber field and in the Format box type “mc”00
This places mc next to 2 zeros and then tacks on the autonumber.
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

 

ADVERTISEMENT


本周最热论坛帖子本周最热论坛帖子

ADVERTISEMENT



ADVERTISEMENT

ADVERTISEMENT


版权所有 © 1996-2023 Cari Internet Sdn Bhd (483575-W)|IPSERVERONE 提供云主机|广告刊登|关于我们|私隐权|免控|投诉|联络|脸书|佳礼资讯网

GMT+8, 27-8-2025 05:57 AM , Processed in 0.116375 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表