Solved

How create autonumber key field with a make table query

Posted on 2013-10-22
6
14,258 Views
Last Modified: 2013-10-22
I have a make table query which when run needs to create a autonumber key field in the resulting table.  The caption for this field needs to be "Item Number".  How can I make this happen?
0
Comment
Question by:SteveL13
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 61

Expert Comment

by:mbizup
ID: 39590975
As far as I know, you cant do that directly.  You'll have to alter the table to add the autonumber field after running the make-table query.

In VBA, something like this:

Dim strSQL as string

' Code to run your make table query goes here
'
' Then ALTER the table...
strSQL = "ALTER TABLE YourTableName ADD ItemNumber AUTOINCREMENT(1, 1)"
CurrentDB.execute strSQL

Open in new window

0
 

Author Comment

by:SteveL13
ID: 39590996
ItemNumber has to have a space between the words.  

Should this then read:

strSQL = "ALTER TABLE YourTableName ADD "Item Number" AUTOINCREMENT(1, 1)"


?
0
 
LVL 48

Expert Comment

by:Dale Fye
ID: 39591000
If you create a table (tbl_Auto) with only a single field (ID) which is set to autonumber and no records, then you can create a query to build your destination table something like:

SELECT tbl_Auto.ID, yourTable.*
INTO yourNewTable
FROM tbl_Auto, yourTable

Since there are no records in tbl_Auto, there will be no records in this new table, but you can then use an append query to append your data to that table:

INSERT INTO yourNewTable (Field1, Field2, Field3)
SELECT Field1, Field2, Field3
FROM yourTable

either way, mbizup's or this one, will require multiple steps.
0
[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

 
LVL 61

Accepted Solution

by:
mbizup earned 500 total points
ID: 39591006
Try square brackets:

strSQL = "ALTER TABLE YourTableName ADD "[Item Number]" AUTOINCREMENT(1, 1)"
0
 
LVL 61

Expert Comment

by:mbizup
ID: 39591017
--->>> Try square brackets:

But as an aside, I'd recommend creating the field with no space in the name (better, standard naming conventions), and querying the resulting table as needed for displaying the name with a space.

Ie this to modify the table:

strSQL = "ALTER TABLE YourTableName ADD ItemNumber AUTOINCREMENT(1, 1)"

and this to retrieve the data for display:

SELECT *, ItemNumber AS [Item Number]
FROM YourTable

again, just standard naming conventions.
0
 

Author Comment

by:SteveL13
ID: 39591030
I removed the quote marks from this line and it works fine.  Thanks.

strSQL = "ALTER TABLE YourTableName ADD "[Item Number]" AUTOINCREMENT(1, 1)"

new line"

strSQL = "ALTER TABLE YourTableName ADD [Item Number] AUTOINCREMENT(1, 1)"
0

Featured Post

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

617 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