Results 1 to 12 of 12
  1. #1
    KingOf206 is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2013
    Location
    Seattle
    Posts
    153

    Use a "Button" to automatically import Data into an access Table **PICS**

    Ok so I have a basic form which allows users to enter single records. However sometimes they need to enter in 100 records and it would be very time consuming to do this 1 by 1. So the idea would be to create a "button" that will import the data from excel into the Access table.

    This function could potentially be done multiple times a day so I would not want to save over the table data each time it was imported, but would rather "append" the data.

    In the following picture I have the form (Left, Frm_WorkInProgress) I am using, there is an Orange "button" called "Import Multiple Trays" I would that button to add all the records from the excel file (right, Book1). The excel file shown would be modified daily and when I import this data into access, I would like it to only add the "new records" and dont change any data in the Table "Tbl_WorkInProgress"

    Click image for larger version. 

Name:	Untitled.jpg 
Views:	18 
Size:	173.5 KB 
ID:	21350

    What is the best way to accomplish this?



    I really appreciate any help that is given.

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    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
    KingOf206 is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2013
    Location
    Seattle
    Posts
    153
    I have tried that one, but it's not working. I will keep trying but I am not getting any good results. When I click the button, absolutely nothing happens...

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Post your code. Have you selected [Event Procedure] in the button Click event?
    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.

  5. #5
    KingOf206 is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2013
    Location
    Seattle
    Posts
    153
    Yes, event procedure is there.

    here is my Written Code:



    Private Sub Command8_Click()
    Dim strPathFile As String, strFile As String, strPath As String
    Dim strTable As String
    Dim blnHasFieldNames As Boolean




    blnHasFieldNames = True


    strPath = "C:\Users\buchanl\Desktop\Book1.xlsx"


    strTable = "Tbl_WorkInProgress"


    strFile = Dir(strPath & "*.xls")
    Do While Len(strFile) > 0
    strPathFile = strPath & strFile
    DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, _
    strTable, strPathFile, blnHasFieldNames


    ' Uncomment out the next code step if you want to delete the
    ' EXCEL file after it's been imported
    ' Kill strPathFile


    strFile = Dir()
    Loop


    End Sub




    HERE IS A SCREEN SHOT:

    Click image for larger version. 

Name:	Untitled.png 
Views:	17 
Size:	113.1 KB 
ID:	21351

  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,929
    Why are you concatenating strPath and strFile? strPath already has the file name. Don't include Book1.xlsx in the strPath string.

    Step debug. What is strPathFile value? Refer to link at bottom of my post for debugging guidelines.
    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
    KingOf206 is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2013
    Location
    Seattle
    Posts
    153
    The Code that is in there is the exact same code as what is in the link that you gave me. I only copied what you gave me and nothing else was extra. I am not a "programmer" so its near impossible for me to answer your questions, although I wish that I could.

    Right now I am stuck. I really do appreaciate your help on this one. I am just not sure what i should be trying now. I looked over the "debuggerr" link that you suggested... I am still looking through it but its not helping me out much. How else can I help you to assist me?

  8. #8
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    The example code does not include Book1.xlsx file name in strPath string. It refers only to folder names. Look at it again.
    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.

  9. #9
    KingOf206 is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2013
    Location
    Seattle
    Posts
    153
    OK I re did my code based on taking out "Book1.xlsx"

    Here it is (And still nothing happens):

    Private Sub Command8_Click()
    Dim strPathFile As String, strFile As String, strPath As String
    Dim strTable As String
    Dim blnHasFieldNames As Boolean




    blnHasFieldNames = True


    strPath = "C:\Users\buchanl\Desktop"


    strTable = "Tbl_WorkInProgress"


    strFile = Dir(strPath & "*.xlsx")
    Do While Len(strFile) > 0
    strPathFile = strPath & strFile
    DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, _
    strTable, strPathFile, blnHasFieldNames


    ' Uncomment out the next code step if you want to delete the
    ' EXCEL file after it's been imported
    ' Kill strPathFile


    strFile = Dir()
    Loop


    End Sub

  10. #10
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    The path must end with \ character to separate it from the file name. That is also demonstrated in the example.
    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.

  11. #11
    KingOf206 is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2013
    Location
    Seattle
    Posts
    153
    June7 You are the FRIGGIN MAN!! That was it!!! I cant believe I over looked that!! Thank you for pointing that out! It now works perfectly!

  12. #12
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    June7 You are the FRIGGIN MAN!!
    Uh.... shouldn't that be: "June7 You are the FRIGGIN WOMAN!!"

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

Similar Threads

  1. Replies: 14
    Last Post: 06-29-2015, 06:29 PM
  2. Replies: 10
    Last Post: 03-15-2013, 05:46 AM
  3. Replies: 1
    Last Post: 08-23-2012, 08:32 AM
  4. Replies: 11
    Last Post: 03-29-2012, 02:32 PM
  5. Replies: 0
    Last Post: 01-11-2012, 12:34 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