By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,089 Members | 2,283 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,089 IT Pros & Developers. It's quick & easy.

Help to make Mdb code work on accdb database

P: 9
Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2.  
  3. Private Sub Form_Load()
  4.     For i = 0 To CurrentDb.TableDefs.Count - 1
  5.         If InStr(CurrentDb.TableDefs(i).Name, "MSys") = 0 Then
  6.             cmbTable.AddItem (CurrentDb.TableDefs(i).Name)
  7.         End If
  8.      Next
  9. End Sub
  10.  
  11. Private Sub xmlBtn_Click()
  12. On Error GoTo Err_xmlBtn_Click
  13.     Create_XML (cmbTable.Column(0))
  14.  
  15. Exit_xmlBtn_Click:
  16.     Exit Sub
  17.  
  18. Err_xmlBtn_Click:
  19.     MsgBox Err.Description
  20.     Resume Exit_xmlBtn_Click
  21.  
  22. End Sub
  23. Private Sub Create_XML(tableName)
  24.  
  25.     Dim Rs As Recordset
  26.  
  27.     Set Rs = CurrentDb.OpenRecordset("SELECT * FROM " & tableName, dbOpenSnapshot)
  28.     If Rs.RecordCount > 0 Then
  29.         Rs.MoveFirst
  30.  
  31.     Dim objDom As MSXML2.DOMDocument60
  32.     Dim objRootElem As IXMLDOMElement
  33.     Dim objMemberElem As IXMLDOMElement
  34.     Dim objMemberName As IXMLDOMElement
  35.  
  36.  
  37.  
  38.  
  39.  
  40.     Set objDom = New MSXML2.DOMDocument60
  41.  
  42.     Set objRootElem = objDom.createElement(tableName)
  43.     objDom.appendChild objRootElem
  44.  
  45.     Do While Not Rs.EOF
  46.         Set objMemberElem = objDom.createElement("Claim")
  47.         objRootElem.appendChild objMemberElem
  48.  
  49.  
  50.         For i = 0 To Rs.Fields.Count - 1
  51.             Set objMemberName = objDom.createElement(Rs.Fields(i).Name)
  52.             objMemberElem.appendChild objMemberName
  53.             objMemberName.Text = Rs.Fields(i).Value
  54.             objMemberElem.appendChild objDom.createTextNode(vbCrLf)
  55.         Next
  56.     Rs.MoveNext
  57.     Loop
  58.  
  59.     Rs.Close
  60.    ' Saves XML data to disk.
  61.    objDom.Save (CurrentProject.Path & "\" & tableName & ".xml")
  62.    MsgBox "Table exported sucessfully."
  63.    End If
  64. End Sub
  65.  
Please assist me to make this code work in access 2013 its giving me error user- defined type not defined. its from mdb, and also to be able to add related tables as child to main table.

Regards
Mar 11 '19 #1
Share this Question
Share on Google+
3 Replies


twinnyfo
Expert Mod 2.5K+
P: 3,284
O bake get,

Your code should work in newer versions of 2013. However, if you are receiving a User-defined error, it is mostl likely that you have not declared a reference in your VBA: Tools | References.

I canít tell you which reference you need because you havenít told us which line of your code produces the error (hint: thatís just a good practice on this forum, to tell us which line produces an error). Itís difficult for us to move beyond without that information.

As a side note, the second line of all of your Modules should be Option Explicit, which forces you to declare all your variables. If this line was present, and you tried compiling/debugging your code, the error-producing line would be highlighted for you.
Mar 11 '19 #2

P: 9
Thank you for your prompt reply, This is the line that is highlighted as error

Dim objDom As MSXML2.DOMDocument60

Regards
Mar 11 '19 #3

twinnyfo
Expert Mod 2.5K+
P: 3,284
Yes - this just confirms my suspicion that you are missing a reference. I can't tell you which reference you need because I don't use XML. But, that same reference will be in your old DB, based upon my description in the previous post. Just make sure you have the same references in both DBs.
Mar 11 '19 #4

Post your reply

Sign in to post your reply or Sign up for a free account.