Results 1 to 3 of 3
  1. #1
    jwalker55 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jan 2012
    Posts
    2

    Importing excel data into table automatically

    Basically, I am creating a database to store performance data for several farms, and I have to pull the data from a records system (exported to excel) and import it into the Access db where I will compile reports from. I'm not sure if I have the db structure setup the way I need it, however. I have a table named Farms, which has fields for Farm Name, address, etc, and a table named PerformanceData that contains all the data imported from the records system. I have a field in the PerformanceData table called FarmID, and I created a relationship between FarmID and the ID field from the Farms table.

    I have created a form where I can open a dialog box, chose the file, and then it will import into the PerformanceData table using DoCmd.TransferSpreadsheet. This all works fine. The question I have, is how do I set it up so I can pick from a list of farms in a drop-down so I can tell it which farm I want to import the data to. As is, when importing, the FarmID field is left empty, since there is no FarmID column in the excel file. I just need to be able to assign each record that is imported from the excel file a FarmID of 1, for example.

    So, if I import the data, and manually put in the FarmID for the imported data. I get something like this:





    Again, maybe I am approaching this entirely wrong. I do not have a ton of Access experience, so I welcome any thoughts.
    Last edited by jwalker55; 01-10-2012 at 11:53 AM.

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,895
    You import one farm's data at a time so all the new records of import would be for one farm? After the import run an UPDATE query to populate these new records with the FarmID.

    In some event (button Click, combobox AfterUpdate), run code (I use only VBA):

    DoCmd.RunSQL "UPDATE tablename Set FieldID=" & Me.comboboxname & " WHERE FieldID Is Null"
    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.

  3. #3
    jwalker55 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jan 2012
    Posts
    2
    Quote Originally Posted by June7 View Post
    You import one farm's data at a time so all the new records of import would be for one farm? After the import run an UPDATE query to populate these new records with the FarmID.

    In some event (button Click, combobox AfterUpdate), run code (I use only VBA):

    DoCmd.RunSQL "UPDATE tablename Set FieldID=" & Me.comboboxname & " WHERE FieldID Is Null"
    Exactly, that sounds like it might work. I will give it a try.

    Thanks!

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

Similar Threads

  1. Importing Excel data to an existing table
    By tonyrhills in forum Import/Export Data
    Replies: 3
    Last Post: 12-23-2011, 09:19 AM
  2. Importing Data from Excel to Access
    By dkatorza in forum Import/Export Data
    Replies: 3
    Last Post: 11-05-2011, 09:17 AM
  3. Store data in Excel automatically is that possible
    By drumaster in forum Import/Export Data
    Replies: 2
    Last Post: 04-27-2011, 03:28 PM
  4. Importing Data From Excel
    By king_bowzow in forum Import/Export Data
    Replies: 1
    Last Post: 09-11-2009, 02:26 AM
  5. Automatically get Excel data
    By TimG in forum Import/Export Data
    Replies: 2
    Last Post: 08-24-2009, 06:38 AM

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