Jim Dettman
jimdettman at earthlink.net
Fri Feb 7 10:43:17 CST 2003
Try this as well:
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
Jim Dettman
President,
Online Computer Services of WNY, Inc.
(315) 699-3443
jimdettman at earthlink.net
-----Original Message-----
From: accessd-admin at databaseadvisors.com
[mailto:accessd-admin at databaseadvisors.com]On Behalf Of Shamil
Salakhetdinov
Sent: Friday, February 07, 2003 9:15 AM
To: AccessD
Subject: [AccessD] Acc97: Creating GUID Autonumber using VBA code...
Hi All,
Is the subj described somewhere? Should I RTFM with more attention and
accuracy?
The following code doesn't produce desired result:
Dim dbs As DAO.Database
Dim tdf As DAO.TableDef
Dim fld As DAO.Field
Set dbs = CurrentDb
Set tdf = dbs.TableDefs("tblTest")
Set fld = tdf.CreateField("fldTest", dbGUID, 16)
fld.Properties("DefaultValue") = "GenGUID()"
tdf.Fields.Append fld
dbAutoIncrField value for Attributes property can't be used at all producing
error 3001 - Invalid argument
Any solutions?
TIA,
Shamil
--
e-mail: shamil at smsconsulting.spb.ru
Web: http://www.smsconsulting.spb.ru/shamil_s
_______________________________________________
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com