Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 820303
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T02:27:13+00:00 2026-05-15T02:27:13+00:00

So I have the below VB that creates an access file in the default

  • 0

So I have the below VB that creates an access file in the default workspace, creates a table, create some fields in that table…just need to know the syntax for setting the first data type/field to autonumber…GUID, Counter, etc will not work as in Access SQL

' error handling usually goes here

dim ws as workspace
dim dbExample as database
dim tblMain as TableDef
dim fldMain as Field
dim idxMain as Index

set ws = workspace(0)

set dbExample = ws.CreateDatabase('string file path')

set tblMain = dbExample.CreateTableDef("tblMain")

set fldMain = tblMain.CreateField("ID", 'right here I do not know what to substitute for dbInteger to get the autonumber type to work )

tblMain.Fields.Append fldMain
etc to create other fields and indexes

so in this line:
set fldMain = tblMain.CreateField(“ID”, dbInteger)
i need to replace the dbInteger with something that VB reconizes as the autonumber property.
i have tried GUID, Counter, Autonumber, AutoIncrement….unfortunately none of these work

anyone know the syntax I am missing here?

Thanks,
Justin

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T02:27:13+00:00Added an answer on May 15, 2026 at 2:27 am

    See Creating an AutoNumber field from code at The access Web.

    Here are the key lines from that linked page:

    Set db = Application.CurrentDb
    Set tdf = db.TableDefs(strTableName)
    ' First create a field with datatype = Long Integer '
    Set fld = tdf.CreateField(strFieldName, dbLong)
    With fld
        ' Appending dbAutoIncrField to Attributes '
        ' tells Jet that its an Autonumber field '
        .Attributes = .Attributes Or dbAutoIncrField
    End With
    With tdf.Fields
        .Append fld
        .Refresh
    End With
    

    BTW, what you’re doing is not DDL.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a very large file that looks like this (see below). I have
So I have this code below that creates a Directory and gives ASPNET permissions
I have a script that appends some rows to a table. One of the
I have a large file, with 1.8 million rows of data, that I need
I am trying to learn more about regular expressions I have one below that
I have a string that is like below. ,liger, unicorn, snipe in other languages
I have a function that resembles the one below. I'm not sure how to
I have noticed that my geocoder is inconsistent in the code shown below because
I have a DataTable that queries out something like below usergroupid...userid......username 1.............1...........John 1.............2...........Lisa 2.............3...........Nathan
I have a few tables that I've defined like the below examples: class TableA

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.