Results 1 to 5 of 5
  1. #1
    Juan4412 is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Dec 2010
    Posts
    209

    Delete Fields In Table With VBA


    I have a table where I want to delete fields (whether they include data or not). The table name is ExcelImport and the field names I want to keep are registrationID, registeredBy, registrationDate. All other fields in the table should be deleted. How is this achieved using VBA/

  2. #2
    JoeM is offline VIP
    Windows 7 32bit Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    I think I would be more apt to use a Make Table Query or an Append Query to write the fields that I want to a new table, and delete the old table afterwards.
    If you are trying to set-up a process that you can use over and over with imported data, I would do the following:
    - Set-up a blank table that has the three fields you want.
    - Import your data into a temporary table
    - Use an Append Query to write the data from your temporary table to your final table
    - Blank out all records in your temporary table for the next run

  3. #3
    JoeM is offline VIP
    Windows 7 32bit Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    If you really want to delete the fields from the one table, have a look at these methods here:
    https://msdn.microsoft.com/en-us/lib.../ff196148.aspx
    https://msdn.microsoft.com/en-us/lib.../ff821417.aspx

    In my opinion, the first method I suggested is easier, in that you can do it all with Macros and doesn't require you to create any custom VBA code.

  4. #4
    Juan4412 is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Dec 2010
    Posts
    209
    Such a simplistic approach, I like it. I have never done a make table query with VBA - what is the syntax for that?

  5. #5
    JoeM is offline VIP
    Windows 7 32bit Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    It is just another Action query.
    See: https://support.office.com/en-us/art...4-e21ad0a94f1b

    Personally, I prefer the approach of setting up a blank table structure first, and then using an Append Query instead.
    The reason for this is simple: you can control the field types of the data, and set up key fields, and indexes exactly the way you want them.
    Otherwise, Access will "guess" as to what field types to use, and may not choose the ones you want. I prefer having the control instead of Access!

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

Similar Threads

  1. Delete does not delete records in evey table
    By LaughingBull in forum Access
    Replies: 5
    Last Post: 09-01-2015, 04:05 PM
  2. delete record if 2 fields are blank
    By rlsublime in forum Access
    Replies: 1
    Last Post: 06-20-2012, 01:58 PM
  3. Replies: 2
    Last Post: 01-24-2012, 02:16 PM
  4. Replies: 11
    Last Post: 03-30-2011, 01:08 PM
  5. Replies: 1
    Last Post: 05-21-2010, 02:22 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