Results 1 to 7 of 7
  1. #1
    xopherira is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2015
    Location
    Indiana
    Posts
    53

    Adding column to first position.

    I am adding a new column to use as primary key. How do I add column to first position?

    Code:
    DoCmd.RunSQL ("ALTER TABLE source_data " & "ADD testDelete COUNTER;")


  2. #2
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    have you tried

    docmd.runsql ("ALTER TABLE Source_Data ADD testDelete COUNTER BEFORE [First Field name];")

  3. #3
    xopherira is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2015
    Location
    Indiana
    Posts
    53
    Yes and I get a Syntax error message.
    Run-time error '3293':
    Syntax error in ALTER table

  4. #4
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    ok must be SQL only then.

    Is there a specific reason you need to alter the field order? you should be able to get around it or display your information in the order you want without altering the table structure, I've got to assume this has to do with importing data from another data source where the field structure is different but then I don't understand why you'd want to do this programmatically when it could be a one time change.

    After doing a quick search I don't know if it's possible to change the field order of a table unless you were to create a new table putting your 'new' column in first then adding all the columns from the existing table, then deleting the original table and renaming the 'new' table to the 'old' table's name. You really shouldn't have to do this though, order of columns should not matter no matter what you're doing.

  5. #5
    xopherira is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2015
    Location
    Indiana
    Posts
    53
    Yes, Importing excel spreadsheet and adding field as "primary key". Yes they are different, need to add and delete before export. I guess I can just add and use where it is placed.

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,919
    Bing: access vba change order of fields in table

    http://www.access-programmers.co.uk/...ad.php?t=75996
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    hah shows what I know. I thought if you used the column index (ordinal position) you'd have to alter the position of every field after it. Should have known better.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Adding a column for DAY in my Query
    By derek7467 in forum Queries
    Replies: 3
    Last Post: 08-07-2013, 04:24 PM
  2. Adding labels in new column
    By Hello World in forum Queries
    Replies: 1
    Last Post: 10-13-2011, 08:57 AM
  3. Replies: 3
    Last Post: 09-28-2011, 04:29 PM
  4. Replies: 5
    Last Post: 09-10-2010, 10:07 AM
  5. Adding a lookup to a column
    By revnice in forum Access
    Replies: 4
    Last Post: 08-16-2010, 12:58 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums