Help: creating table with autonumber data type 
Author Message
 Help: creating table with autonumber data type

I have been trying to use a vb program to create a table in an Access
database where one of the fields uses the autonumber data type.  I get an
error when I try to use autonumber as a data type, but not with other data
types  Why is this?  How can I get it to work?

Thanks.
Steve Eisenberg



Tue, 06 Mar 2001 03:00:00 GMT  
 Help: creating table with autonumber data type
I am assuming VB 5.0 and DAO 3.5:

Private Sub Command1_Click()
    Dim ws As Workspace
    Dim db As Database
    Dim td As TableDef
    Dim f As Field
    Set ws = Workspaces(0)
    If Dir(App.Path & "\test.mdb") <> "" Then
        Kill App.Path & "\test.mdb"
    End If
    Set db = ws.CreateDatabase(App.Path & "\test.mdb", dbLangGeneral)
    Set td = db.CreateTableDef("TestTable")
    Set f = td.CreateField("AutoNum", dbLong)
    f.Attributes = dbAutoIncrField
    td.Fields.Append f
    Set f = Nothing
    Set f = td.CreateField("Test", dbText, 25)
    td.Fields.Append f
    Set f = Nothing
    db.TableDefs.Append td
    Set td = Nothing
    db.Close
    Set ws = Nothing
End Sub

Hope this helps

---------------------------------------------------------
Come visit Prime Computer Solutions
at www.prime-solutions.com.  We offer
low cost ActiveX controls and free
Visual Basic code samples.



Tue, 06 Mar 2001 03:00:00 GMT  
 Help: creating table with autonumber data type
This is what I use:

Public Sub CreateWidgetTable(mTableName As String)
    Dim mNewFields(23) As Field
    Dim rsNewWidgets As TableDef

    Set rsNewWidgets = dbNewUser.CreateTableDef(mTableName)

    Set mNewFields(0) = rsNewWidgets.CreateField("WidgetID", dbLong)
    mNewFields(0).Attributes = dbAutoIncrField

    Set mNewFields(1) = rsNewWidgets.CreateField("ThingID", dbLong)
    mNewFields(1).Size = 5

    For I = 0 To 22
        rsNewVehicles.Fields.Append mNewFields(I)
    Next

    dbNewUser.TableDefs.Append rsNewVehicles

ETC.

--
Merf

www.milemate.com

Quote:

>I have been trying to use a vb program to create a table in an Access
>database where one of the fields uses the autonumber data type.  I get an
>error when I try to use autonumber as a data type, but not with other data
>types  Why is this?  How can I get it to work?

>Thanks.
>Steve Eisenberg




Tue, 06 Mar 2001 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Help: creating table with autonumber data type

2. Data Type Conversion Error when creating table in VBA

3. Add a table field with type autonumber

4. Creating a field of type "autonumber"

5. Creating a field of type "autonumber"

6. Create AutoNumber type field

7. Creating Access field: AutoNumber Type????

8. AutoNumber data type problem!!

9. Data type mismatch with AutoNumber

10. SQL problems with Autonumber Data Type

11. Autonumber Data Type?

12. How to use Autonumber field type with VB-6 Data Environment Designer

 

 
Powered by phpBB® Forum Software