R
RB Smissaert
Trying to install the ADO reference library in Word (2000 to 2003), but
there are some problems with this.
One of them is that variables can't be declared as ADO objects if this is
not installed, causing the error:
compile error: User-defined type not defined
So this can't work: Public ADOConn As ADODB.Connection
I can declare as variant and then do:
Set ADOConn = CreateObject("ADODB.Connection")
rather than
Set ADOConn = New ADODB.Connection
But then for some reason ADO doesn't install.
I just can't figure this out and wonder what the best way is to approach
this.
This is my routine that installs ADO:
Sub AddADO()
'this has to be in a different module as the module where there is the
'declaration: Public ADOConn As ADODB.Connection, otherwise there will
be
'a compile error: User-defined type not defined
'the other option would be to declare ADOConn as variant
'------------------------------------------------------------------------
Dim R
For Each R In Application.VBE.ActiveVBProject.References
If R.GUID = "{00000205-0000-0010-8000-00AA006D2EA4}" And R.Major = 2
Then
Exit Sub
End If
Next
'although usually the ADO version will be higher, doing Minor:=0 will
install
'the higher version if available. On the other hand when you specify
Minor:=5
'and only a lower version is available, this can't be installed
'---------------------------------------------------------------------------
-
Application.VBE.ActiveVBProject.References.AddFromGuid _
GUID:="{00000205-0000-0010-8000-00AA006D2EA4}", _
Major:=2, Minor:=0
Exit Sub
NOTFOUND:
MsgBox "CAN'T RUN THIS CODE" & vbCrLf & vbCrLf & _
"ADO 2.x IS NOT ON THIS COMPUTER"
End Sub
Thanks for any advice.
RBS
there are some problems with this.
One of them is that variables can't be declared as ADO objects if this is
not installed, causing the error:
compile error: User-defined type not defined
So this can't work: Public ADOConn As ADODB.Connection
I can declare as variant and then do:
Set ADOConn = CreateObject("ADODB.Connection")
rather than
Set ADOConn = New ADODB.Connection
But then for some reason ADO doesn't install.
I just can't figure this out and wonder what the best way is to approach
this.
This is my routine that installs ADO:
Sub AddADO()
'this has to be in a different module as the module where there is the
'declaration: Public ADOConn As ADODB.Connection, otherwise there will
be
'a compile error: User-defined type not defined
'the other option would be to declare ADOConn as variant
'------------------------------------------------------------------------
Dim R
For Each R In Application.VBE.ActiveVBProject.References
If R.GUID = "{00000205-0000-0010-8000-00AA006D2EA4}" And R.Major = 2
Then
Exit Sub
End If
Next
'although usually the ADO version will be higher, doing Minor:=0 will
install
'the higher version if available. On the other hand when you specify
Minor:=5
'and only a lower version is available, this can't be installed
'---------------------------------------------------------------------------
-
Application.VBE.ActiveVBProject.References.AddFromGuid _
GUID:="{00000205-0000-0010-8000-00AA006D2EA4}", _
Major:=2, Minor:=0
Exit Sub
NOTFOUND:
MsgBox "CAN'T RUN THIS CODE" & vbCrLf & vbCrLf & _
"ADO 2.x IS NOT ON THIS COMPUTER"
End Sub
Thanks for any advice.
RBS