查看: 1090|回复: 1
|
<--这个 coding set auto increament要怎样的改呢?
[复制链接]
|
|
转贴
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
 
如果我不要random的text呢?可以吗? |
|
|
|
|
|
|
|

楼主 |
发表于 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. |
|
|
|
|
|
|
| |
本周最热论坛帖子
|