+ Reply to Thread
Results 1 to 5 of 5

Get data from MS Access database but not the primary Column

  1. #1
    Forum Contributor
    Join Date
    06-07-2016
    Location
    Manila
    MS-Off Ver
    365
    Posts
    292

    Get data from MS Access database but not the primary Column

    Hi All,

    Will be needing your help again, so far I have a SQL query that will paste all data from MS Access.

    However, I dont want the excel to include the Primary Key Column.

    Is there a way to do this?

    Thanks!

  2. #2
    Valued Forum Contributor
    Join Date
    03-16-2017
    Location
    UK
    MS-Off Ver
    2016
    Posts
    371

    Re: Get data from MS Access database but not the primary Column

    Create a query in Access that outputs the fields you want, and then create a connection to that query from Excel.
    Design everything to be as simple as possible, but no simpler.

  3. #3
    Forum Contributor
    Join Date
    06-07-2016
    Location
    Manila
    MS-Off Ver
    365
    Posts
    292

    Re: Get data from MS Access database but not the primary Column

    Hi Thanks.

    But im already done with that part.

    What I'm asking is, is there a better way of writing this code?

    sQL = "SELECT [Col1], [Col2], [Col3], [Col4], and so on until Col89 FROM myDB"

    The above statement is working however it's pretty long for a code.

    Col0 = my primary key in ms access.

    I'm wondering if it is possbile to be like this.

    sQL = "SELECT * FROM myDB WHERE (EXCLUDING Pimary Key Column)"

    So that's what I'm actually asking.

  4. #4
    Valued Forum Contributor
    Join Date
    03-16-2017
    Location
    UK
    MS-Off Ver
    2016
    Posts
    371

    Re: Get data from MS Access database but not the primary Column

    Hmm no it's not really possible, and that's by design because you should explicitly state the columns you want to return. You only have to build the string once. Alternatively you could just hide or delete the primary key column in Excel.

  5. #5
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2404 Win 11 Home 64 Bit
    Posts
    23,861

    Re: Get data from MS Access database but not the primary Column

    In your SQL statement, if your PK is in the first column, then don't Select that column.
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. copy data from one access database to another access database
    By aman1234 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-21-2014, 09:03 AM
  2. Replies: 2
    Last Post: 07-05-2013, 09:37 AM
  3. [SOLVED] How to show column headers in listbox from access database?
    By Kiran2012 in forum Access Programming / VBA / Macros
    Replies: 4
    Last Post: 11-26-2012, 10:30 AM
  4. Access VBA to add a primary key (first field) after importing to access
    By ewong in forum Access Programming / VBA / Macros
    Replies: 5
    Last Post: 09-14-2012, 08:57 PM
  5. Primary key for database
    By yes sir in forum Access Tables & Databases
    Replies: 4
    Last Post: 08-21-2010, 09:20 PM
  6. getting unique records similar to the primary key in access
    By Alok in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 01-27-2006, 05:10 PM
  7. importing data from access-database access file
    By amrezzat in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-22-2005, 04:25 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1