system.XML in VB6

  • Thread starter Thread starter Pete Morris
  • Start date Start date
P

Pete Morris

I want to do some programming using XML in VB6, specifically
MS Access.

I have some sample VB.Net code that I can use. It has
<< Imports System.XML >> at the start of the code.

What's the VB6 equivalent of this? I've tried using that, but it
just gives an error message. Or maybe I'm putting it in the wrong
place. And it doesn't recognise XML operations without it.
 
A dotnet namespace such as System.XML is utterly meaningless in a VB6/VBA
environment, and nor is there any equivalent: VB.Net is not simply a more
recent version of VB6, it is totally new from the ground up and is
profoundly different.

It's impossible to suggest how you might do what you want in Access without
knowing more about it. "Programming using XML" does not give a great deal
to go on!
 
Pete said:
I want to do some programming using XML in VB6, specifically
MS Access.

VB6 said:
I have some sample VB.Net code that I can use. It has
<< Imports System.XML >> at the start of the code.

What's the VB6 equivalent of this?

In VB6, you can set a reference to Microsoft XML, version 2.0, or any of the
later versions. Using that, you can do a variety of XML things. If you are
working in MSAccess, you could try doing the same thing, I have no idea if it
would work there.
 
Baz said:
A dotnet namespace such as System.XML is utterly meaningless in a VB6/VBA
environment, and nor is there any equivalent: VB.Net is not simply a more
recent version of VB6, it is totally new from the ground up and is
profoundly different.

It's impossible to suggest how you might do what you want in Access
without knowing more about it. "Programming using XML" does not give a
great deal to go on!


Just for a start, how do create an XML document object in Access?
Once I can do that, I think I can work out the rest.


In my VB.Net example it's
<< Dim xmlDoc As XmlDocument = New XmlDocument >>


I also have an Excel example in which it goes like this

<< Dim xmlDoc As MSXML2.DOMDocument
Set xmlDoc = New MSXML2.DOMDocument >>


But neither of these work in Access. It gives me an error message
"user defined type not defined"

Do I need to add support for XML to Access, or something?
 
Steve Gerrard said:
VB6 <> MSAccess.VBA

vba6.dll is the core language of both VB6 and Access. Very likely, there
would be no, or little, difference between VB6 and VBA in using XML.

Larry Linson
Microsoft Access MVP
 
Dear Pete:

What version of Access are you using? Have you added a reference to MSXML?
 
Fred Boer said:
Dear Pete:

What version of Access are you using? Have you added a reference to MSXML?


Access 2003.

What does it mean to "add a reference" and how do I do it?
 
Pete Morris said:
Access 2003.

What does it mean to "add a reference" and how do I do it?

Open the Access code window. On the Tools menu, click "References". Scroll
down the list looking for the library you want to reference, and when you've
found it tick the check box.
 
See Baz's response. Add a reference to, say, Microsoft XML, v3.0 and try it
again...
 
I also have an Excel example in which it goes like this

<< Dim xmlDoc As MSXML2.DOMDocument
Set xmlDoc = New MSXML2.DOMDocument >>

But neither of these work in Access. It gives me an error message
"user defined type not defined"

Do I need to add support for XML to Access, or something?

That's what you need, but you have to have a reference to the MSXML
library for the specific typese to be usable. I don't know exactly
how you do that in VB6. In Access, it's on the TOOLS menu in the
VBE.

Alternatively, you could use late binding, like this:

Dim xmlDoc As Document
Set xmlDoc = CreateObject("Microsoft.XMLHTTP")

You won't get the Intellisense in Access with this, but it obviates
any need for the reference (which can break if the path is not
compatible on a particular machine).
 
What does it mean to "add a reference" and how do I do it?

Others have explained how to add the reference, but I recommend
using Late Binding, instead, in which case you use generic variables
of type Object. I just posted this in another reply:

Dim xmlDoc As Document
Set xmlDoc = CreateObject("Microsoft.XMLHTTP")

That *should* have been:

Dim xmlDoc As Object
Set xmlDoc = CreateObject("Microsoft.XMLHTTP")

I'll post a followup correcting the erroneous post.
 
Alternatively, you could use late binding, like this:

Dim xmlDoc As Document
Set xmlDoc = CreateObject("Microsoft.XMLHTTP")

Of course, that should read:

Dim xmlDoc As Object
Set xmlDoc = CreateObject("Microsoft.XMLHTTP")

Sorry about the typo!
 
David W. Fenton said:
Others have explained how to add the reference, but I recommend
using Late Binding, instead, in which case you use generic variables
of type Object. I just posted this in another reply:

Dim xmlDoc As Document
Set xmlDoc = CreateObject("Microsoft.XMLHTTP")

That *should* have been:

Dim xmlDoc As Object
Set xmlDoc = CreateObject("Microsoft.XMLHTTP")

I'll post a followup correcting the erroneous post.

Agreed. Unless you are a micro-efficiency nut then late-binding is always
the way to go.

I like to use a hybrid approach: early binding while developing, to get the
benefits of intellisense, and then switch to late binding for final testing
and production.
 
Back
Top