ADOX Autoincrement property gives runtime error with VB6

Posted on 2004-11-19
Last Modified: 2008-02-01
Experts, your help please

I'm attempting to use ADOX in VB6 to add an autoincrement field to a Table in an Access database and make it the primary key

The following snippet gvies a runtime error when it attempts to set the Autoincrement property to true

                       Set oTable = oTables.Item("MyTable")
                       With oTable
                            .Columns.Append "PriKey", adInteger
                            .Columns("PriKey").Properties("Autoincrement") = True
                            .Keys.Append "MyTable", adKeyPrimary, .Columns("PriKey")
                       End With

I've tried various alternatives for this code but always the error is always at the same point.

Solutions or workarounds, please
Question by:Gordon_Atherley
    LVL 29

    Accepted Solution


    Author Comment


    Now I see the technique. Append an index which becomes the primary key.

    This is the insight I needed, thank you very much Leon


    LVL 29

    Expert Comment

    No problem.  Thanks for the grade,


    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Join & Write a Comment

    Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
    Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
    Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
    Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now