Results 1 to 13 of 13
  1. #1
    artec is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Dec 2011
    Posts
    11

    Import xml file to table

    Hi, Is it possible to import xml file and add to all tables columns with filename( in all imported records) ?

    This is my code:
    Code:
    Dim strFolder As String
    Dim EFile As Object
    strFolder = "C:\
    Desktop\lk\1\"
    strFile = Dir(strFolder & "*.xml")
    Do While Len(strFile) > 0
    Application.ImportXML strFolder & strFile, acAppendData
    strFile = Dir()
    .
    .

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,926
    What is the issue? Does it work? If not, what happens - error message, wrong results, nothing?

    What do you mean by 'add to all tables columns with filename'?
    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
    artec is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Dec 2011
    Posts
    11
    Import files works without any errors but it makes a few tables from one file (without ralationship). I need to force import all files to one table or a few tables with key, to make relations. File name is unique and I think that good way will be insert it to new columns in all new tables.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,926
    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
    artec is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Dec 2011
    Posts
    11
    Quote Originally Posted by June7 View Post
    I found other idea but somethig works wrong.
    I have code to import one file like this:
    Code:
    DoCmd.SetWarnings FalseConst acAppendData = 2
    Set objAccess = CreateObject("Access.Application")
    objAccess.OpenCurrentDatabase "C:\path\xml.accdb"
    objAccess.ImportXML "" & Me.lstFileList.Value & "", acAppendData
    DoCmd.RunSQL "UPDATE TAB1 SET [IDTMP] = '" & Me.Tekst6.Value & "' WHERE [ID] is null ;"
    .
    This part
    Code:
    objAccess.ImportXML "" & Me.lstFileList.Value & "", acAppendData.
    import files which are listed from call function. This works great. Field [IDTMP] is empty and I need update it with this sql
    Code:
    DoCmd.RunSQL "UPDATE TABELA SET [IDTMP] = '" & Me.Tekst6.Value & "' WHERE [ID] is null ;".
    And now is problem.Between this two parts of code import and update access can't refresh table TAB1 and update doesn't work. Sometimes works and updates field [IDTEMP]. Sometimes when I import next xml file updates record for first file, sometimes updates two records with the same Me.Tekst6.Value.
    Probably is something wrong with refresh table.
    One more. If I share import and update for two different button and use after import system button "Refresh all" and update sql everything works great.What is wrong ?

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,926
    I don't know why Refresh would be needed after update is executed. Do you have the tables open when this code runs? Also don't know why sometimes fails. I would have to test code with data if you want to provide files for analysis. Follow instructions at bottom of my post.
    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
    artec is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Dec 2011
    Posts
    11
    Ok. There are files for analysis. Thank You.

  8. #8
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,926
    Your attached zip is corrupted and I can't open it to extract files.
    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
    artec is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Dec 2011
    Posts
    11
    Please try to change extession to rar. It was comressed by winrar. I've download this file and it's ok. I did new zipped version and attache it.
    Attached Files Attached Files

  10. #10
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,926
    I can't open rar, only Windows compression. I did get the last zip to extract.

    When I click the Import and Update button, get message "The expression On Click you entered as the event property setting produced the following error: A problem occrred while Microsoft Office Access was communicating with the OLE server or ActiveXControl."

    I was testing with A2007. Will try again later with A2010.

    Any idea why I am getting this error?
    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
    artec is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Dec 2011
    Posts
    11
    I was testing it on 2007 and 2010 and its ok. Please put Test.accdb, Test1.xml, Test2.xml files to C:\XML on your disk. This is my location for this database and files. I hope that help you to run it.

  12. #12
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,926
    Still get same error. All of the VBA event procedures trigger this error. I got the following to work in my db:

    Private Sub Polecenie8_Click()
    Application.ImportXML "C:\XML\Test1.xml", acAppendData
    DoCmd.RunSQL "UPDATE TABELA SET [IDTMP] = 'test' WHERE [IDTMP] is null;"
    End Sub
    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.

  13. #13
    artec is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Dec 2011
    Posts
    11
    I dont know what is, but your code which you got works perfectly without any errors and makes procedure what I need. Firstly file is imported and next table is updated. Everything works right. Thank You very much !

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

Similar Threads

  1. Import .TXT file into SQL Server 2005 Table
    By taimysho0 in forum SQL Server
    Replies: 1
    Last Post: 05-23-2012, 03:02 PM
  2. Import txt file into Access Table
    By redbull in forum Import/Export Data
    Replies: 3
    Last Post: 05-02-2012, 09:32 AM
  3. Replies: 0
    Last Post: 12-08-2011, 09:12 AM
  4. Replies: 5
    Last Post: 12-01-2011, 05:38 PM
  5. Import XML file
    By randolphoralph in forum Programming
    Replies: 1
    Last Post: 01-22-2010, 09:12 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