Results 1 to 8 of 8
  1. #1
    crownedzero is offline Novice
    Windows XP Access 2003
    Join Date
    Jun 2009
    Posts
    19

    Import and Modify data

    I'm working on building a command button to import data into Access. I've tried some of the listed methods in the forums here and I must be missing something. I need to import an Excel spreadsheet into Access, I'd also like it to change all negative values in the "Available" column to 0.

    Can anyone give me a "for Dummies" explanation of how to accomplish this?

    Again, I know this is frequently referred to on the boards here, but I have yet to get one to work for me. If it matters I'm using Excel 2003.

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Can you achieve the import you want?

  3. #3
    crownedzero is offline Novice
    Windows XP Access 2003
    Join Date
    Jun 2009
    Posts
    19

    Form button to run update query

    I have a update query to update negatives to zero, question is how do I add that to the button event procedures?

  4. #4
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Show us the Button Event procedure.

  5. #5
    crownedzero is offline Novice
    Windows XP Access 2003
    Join Date
    Jun 2009
    Posts
    19
    I think I got it figured out, it may not be the cleanest. If I wanted to update this to allow the user to choose which file to import how would I go about it?

    I included a bit of code to close the table if it should be open but I've noticed it doesn't function like it should. If form button is clicked while the table is open the event will not run. Thoughts?

    Code:
    Private Sub Import_Data_Click()
     
        DoCmd.Close acTable, "TBL_Inventory"
        DoCmd.DeleteObject acTable, "TBL_Inventory"
        DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, "TBL_Inventory", "C:\Mydir\myfile.xls", True
        DoCmd.RunSQL "ALTER TABLE TBL_Inventory ALTER COLUMN Size Double"
        DoCmd.RunSQL "ALTER TABLE TBL_Inventory ALTER COLUMN Available Integer"
     
    End Sub

  6. #6
    crownedzero is offline Novice
    Windows XP Access 2003
    Join Date
    Jun 2009
    Posts
    19
    Code:
    Private Sub Import_Data_Click()
        
        On Error Resume Next
            
            DoCmd.Close acTable, "TBL_Inventory"
            DoCmd.DeleteObject acTable, "TBL_Inventory"
            DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, "TBL_Inventory", "C:\Mydir\myfile.xls", True
            DoCmd.RunSQL "ALTER TABLE TBL_Inventory ALTER COLUMN Size Double"
            DoCmd.RunSQL "ALTER TABLE TBL_Inventory ALTER COLUMN Available Integer"
        
    End Sub
    The update query I have written is called QRY_Negatives_To_Zero, any values <0 become 0.

  7. #7
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Quote Originally Posted by crownedzero View Post
    If I wanted to update this to allow the user to choose which file to import how would I go about it?
    Here's the API I would use to let the user pick a file: http://www.mvps.org/access/api/api0001.htm

  8. #8
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    I just put your two threads together. I was going around in circles until I figured out you had two threads on the same subject. Please do not do that. I'm going to take a break for a while now.

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

Similar Threads

  1. Import from various folders
    By Statique in forum Import/Export Data
    Replies: 2
    Last Post: 07-02-2009, 06:10 AM
  2. Import from SQl server
    By NaatuGaadu in forum Import/Export Data
    Replies: 2
    Last Post: 06-18-2009, 09:56 AM
  3. Import from MS Works
    By jerald in forum Import/Export Data
    Replies: 0
    Last Post: 03-17-2009, 08:00 AM
  4. Validation on import
    By andy_42 in forum Import/Export Data
    Replies: 1
    Last Post: 10-23-2006, 03:52 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