VBA - XML code causing compile error (1 Viewer)

Cosmos75

Registered User.
Local time
Today, 15:29
Joined
Apr 22, 2002
Messages
1,281
I have some code from an database that I did not build that is giving me trouble when trying to compile. It starts with these three declarations.

Code:
Dim oDoc As DOMDocument

...

Dim wrt As MXXMLWriter40
Dim atrs As New SAXAttributes30

I have 'Microsoft XML, v6.0' checked in my VBA references and the file for it does exist on my computer. WHen I try to compile I get a "User-defined type not defined" compile error.

I tried going through this link but I think I have the XML DOM already installed, which is what I think I need. But I'm not sure, hence the reason for my post.
A Beginner's Guide to the XML DOM: https://msdn.microsoft.com/en-us/library/aa468547.aspx


I don't think the oDoc declaration is needed, but I'm not 100% sure. The only code use by it is as follows:
Code:
Dim oDoc As DOMDocument

Private Sub Form_Unload(Cancel As Integer)
    ReleaseObjects
End Sub

Private Sub ReleaseObjects()
    Set oDoc = Nothing
End Sub

Not sure if that is actually doing anything.

Anyone have any idea what I'm missing?
Thanks!
 

Ranman256

Well-known member
Local time
Today, 16:29
Joined
Apr 9, 2015
Messages
4,339
if you are not using DOMDocument, dont put it in references. (or DIM)
I dont see code where you call it.
 

Cosmos75

Registered User.
Local time
Today, 15:29
Joined
Apr 22, 2002
Messages
1,281
Yeah, I agree. Just that this isn't code I wrote but rather code I inherited from someone else. I don't even know what reference "DOMDocument" requires.
 

Cosmos75

Registered User.
Local time
Today, 15:29
Joined
Apr 22, 2002
Messages
1,281
I think I managed to fix it by changing

Code:
Dim wrt As MXXMLWriter40
Dim atrs As New SAXAttributes30

to

Code:
Dim wrt As MSXML2.MXXMLWriter60
Dim atrs As New MSXML2.SAXAttributes60

And commenting out
Code:
'Dim oDoc As DOMDocument

...

'Set oDoc = Nothing
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 20:29
Joined
Sep 12, 2006
Messages
15,614
I am surprised you don't need DOMDocument, or that including it crashes your app.

A DOMDocument is (a pointer to) the entire XML File.
 

Cosmos75

Registered User.
Local time
Today, 15:29
Joined
Apr 22, 2002
Messages
1,281
Gemma/Dave,

Wish I could tell you more but I've never dealt with XML before so I don't know exactly what is is going on. Other that what I posted there's no other usage of the oDoc object.

I have been adding othter code to the vile, and it wouldn't compile because of that eDoc declaration. And I can't figure out what reference I might be missing. Since it doesn't seem to be doing anything, I just decided to comment it out.

Think it may have started out using DOM then switched over to SAX, i.e. "Simple API for XML". Again, I've never dealt with it so it's just what I've been able to find on the internet when I search for those declarations.

A Beginner's Guide to the XML DOM

SAX and VB 6

This one is what led me to try changing the declaration.
MyExtractor Class (XML Extractor)
 

Users who are viewing this thread

Top Bottom