Results 1 to 3 of 3
  1. #1
    obakeng is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Mar 2019
    Posts
    2

    Question Please help me get this code to work in access 2013


    Code:
    Option Compare Database
    Private Sub Form_Load()
        For i = 0 To CurrentDb.TableDefs.Count - 1
            If InStr(CurrentDb.TableDefs(i).Name, "MSys") = 0 Then
                cmbTable.AddItem (CurrentDb.TableDefs(i).Name)
            End If
         Next
    End Sub
    Private Sub xmlBtn_Click()
    On Error GoTo Err_xmlBtn_Click
        Create_XML (cmbTable.Column(0))
    Exit_xmlBtn_Click:
        Exit Sub
    Err_xmlBtn_Click:
        MsgBox Err.Description
        Resume Exit_xmlBtn_Click
        
    End Sub
    Private Sub Create_XML(tableName)
       
        Dim Rs As Recordset
        
        Set Rs = CurrentDb.OpenRecordset("SELECT * FROM " & tableName, dbOpenSnapshot)
        If Rs.RecordCount > 0 Then
            Rs.MoveFirst
        
        Dim objDom As MSXML2.DOMDocument60
        Dim objRootElem As IXMLDOMElement
        Dim objMemberElem As IXMLDOMElement
        Dim objMemberName As IXMLDOMElement
       
            
    
        Set objDom = New MSXML2.DOMDocument60
       
        Set objRootElem = objDom.createElement(tableName)
        objDom.appendChild objRootElem
        
        Do While Not Rs.EOF
            Set objMemberElem = objDom.createElement("Claim")
            objRootElem.appendChild objMemberElem
           
            
            For i = 0 To Rs.Fields.Count - 1
                Set objMemberName = objDom.createElement(Rs.Fields(i).Name)
                objMemberElem.appendChild objMemberName
                objMemberName.Text = Rs.Fields(i).Value
                objMemberElem.appendChild objDom.createTextNode(vbCrLf)
            Next
        Rs.MoveNext
        Loop
        
        Rs.Close
       ' Saves XML data to disk.
       objDom.Save (CurrentProject.Path & "\" & tableName & ".xml")
       MsgBox "Table exported sucessfully."
       End If
    End Sub
    its giving me error user- defined type not defined, then highlight
    Code:
     objDom As MSXML2.DOMDocument60

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,722
    Check your references to see if you have included
    Microsoft XML, V6.0


    I also recommend you have an Option Explicit as second line in each module.
    Attached Thumbnails Attached Thumbnails xmlref.PNG  

  3. #3
    obakeng is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Mar 2019
    Posts
    2
    Thank you very much, I managed to get it working from youradvice.
    I am new in access programing and so far I have managed tomake a working database, now my challenge is to transfer some invoices from myinvoice table to xml, which will now be emailed to a third party.
    Now can I make this code to transfer a query instead of a table? In a query I will be able to filter whichdata I want to transfer. Also can it addadditional queries that have a relationship to the main query?
    E.g.
    Objrootelementwill be “ClaimBatch”
    First objMemberElem will be “Batchheader” frombatchheader query
    second objMemberElemwill be “Claim” from claim query
    third objMemberElemwill be “line” from line query
    forth objMemberElemwill be “Diagnosis” from diagnosis query
    firth objMemberElemwill be “Batchtrailer” from batchtrailer query

    All thisqueries will be having a common relationship of “Transactionno” which I can useas a filter in the form. So instead ofthe form selecting a table, I could be entering a transaction number then when Iclick on the button it produces an xml file

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

Similar Threads

  1. Replies: 7
    Last Post: 04-19-2018, 12:57 PM
  2. ACCDE does not work Access 2013
    By azhar2006 in forum Forms
    Replies: 4
    Last Post: 03-08-2014, 11:21 PM
  3. Replies: 6
    Last Post: 10-24-2013, 04:58 PM
  4. Replies: 3
    Last Post: 06-19-2013, 04:45 PM
  5. Replies: 4
    Last Post: 03-08-2013, 08:54 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