access 2013 vba - create new table with autonumber field and set as primary key

RCBricker

Well-known Member
Joined
Feb 4, 2003
Messages
1,560
ok so I have set up a Boolean function to see if a table exists before importing data. Now I want to create the table if it doesn't exist. I only need one field with that field being both an autonumber field and the primary key.

Any ideas?

I was looking at the create table but can not figure out how to write the autonumber attribute to the command.

I was thinking along the lines of:

Code:
dbF.Execute "CREATE TABLE strTBLPname " _ 
        & "(REC_NUM CHAR CONSTRAINT MyFieldConstraint " _ 
        & "PRIMARY KEY);"

but not sure what to replace the CHAR with to get it to be an autonumber.
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Nevermind figured it out.

For anyone looking to for the answer

Code:
    strADDtbl = "CREATE TABLE [" & strTBLPname & "]([REC_NUM] " _
        & "AUTOINCREMENT PRIMARY KEY)"
 
    DoCmd.RunSQL strADDtbl, False
    DoEvents
    Application.RefreshDatabaseWindow
 
Upvote 0

Forum statistics

Threads
1,221,814
Messages
6,162,132
Members
451,743
Latest member
matt3388

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top