S
Scott
My problem is that access apps that need the ADOX Library running under Win
XP require "ADO Ext. 2.8 for DLL and Security". When run on Vista, the ADOX
version must be "ADO Ext. 6.0 for DLL and Security".
I have created working functions to add and remove the "ADOX" Library. The
function ReferenceFromGuid() listed below as CODE #3 adds the library
correctly when tested in the VBE Immediate Window environment. My function
RemoveReference() CODE #4 also removes the library correctly within the test
VBE environment.
However, when I try to load the ADOX reference from my app's first opened
form's "OnOpen" Event, it never executes. The same happens when I try to
remove the library from the last form closed "On Close" Event. The
ReferenceFromGuid() function will not execute.
What could cause these working functions to simply be bypassed?
I desperately need a way to load the appropriate version of the ADOX library
within my app, depending on whether the app is being run using XP or Vista?
My code listed in CODE #1 would do the job if my functions would execure at
runtime, but for some reason, access seems to ignore them. Anyone have any
ideas?
Functions
***********************************************************************
** CODE #1 **
Private Sub Form_Load() ' opens first via AutoExec macro using Form_Load
event of a hidden form
If RefExists("ADOX") = False Then 'Load Microsoft ADO Ext. 2.x for DDL &
Security
If IsWinXP() Then
'Load a reference to the ADO Ext. 2.8 for DLL and Security
Call ReferenceFromGuid("{00000600-0000-0010-8000-00AA006D2EA4}",
2, 8)
ElseIf IsWinVista() Then
'Load a reference to the ADO Ext. 2.6 for DLL and Security
Call ReferenceFromGuid("{00000600-0000-0010-8000-00AA006D2EA4}",
6, 0)
End If
End If
End Sub
** CODE #2 **
Public Function RefExists(sLibrary As String) As Boolean
Dim Refs As References, r As Reference
Set Refs = Application.References
For Each r In Refs
If r.Name = sLibrary Then
Debug.Print r.Name, "*** Exists"
RefExists = True
Else
Debug.Print r.Name, r.Kind, r.Major, r.Minor, r.FullPath
RefExists = False
End If
Next r
End Function
** CODE #3 **
Function ReferenceFromGuid(sGuid As String, iMajor As Integer, iMinor As
Integer) As Boolean
' Usage:
'creates a reference to the ADO Ext. 2.8 for DLL and Security
' Call ReferenceFromGuid("{00000600-0000-0010-8000-00AA006D2EA4}", 2, 8)
Dim ref As Reference
On Error GoTo Error_ReferenceFromGuid
Set ref = References.AddFromGuid(sGuid, iMajor, iMinor)
ReferenceFromGuid = True
Exit_ReferenceFromGuid:
Exit Function
Error_ReferenceFromGuid:
Select Case Err.Number
Case 32813 ' Name conflicts with existing module, project or object
library. The reference is already set!
ReferenceFromGuid = True
Case Else
MsgBox ("Error # " & str(Err.Number) & " was generated by " &
Err.Source & Chr(13) & Err.Description)
ReferenceFromGuid = False
Resume Exit_ReferenceFromGuid
End Select
End Function
** CODE #4 **
Function RemoveReference(sLibrary As String)
Dim ref As Reference
Set ref = References(sLibrary) '[ACG PDF Pro Plus Mail Library]
'ADODB
References.Remove ref
End Function
XP require "ADO Ext. 2.8 for DLL and Security". When run on Vista, the ADOX
version must be "ADO Ext. 6.0 for DLL and Security".
I have created working functions to add and remove the "ADOX" Library. The
function ReferenceFromGuid() listed below as CODE #3 adds the library
correctly when tested in the VBE Immediate Window environment. My function
RemoveReference() CODE #4 also removes the library correctly within the test
VBE environment.
However, when I try to load the ADOX reference from my app's first opened
form's "OnOpen" Event, it never executes. The same happens when I try to
remove the library from the last form closed "On Close" Event. The
ReferenceFromGuid() function will not execute.
What could cause these working functions to simply be bypassed?
I desperately need a way to load the appropriate version of the ADOX library
within my app, depending on whether the app is being run using XP or Vista?
My code listed in CODE #1 would do the job if my functions would execure at
runtime, but for some reason, access seems to ignore them. Anyone have any
ideas?
Functions
***********************************************************************
** CODE #1 **
Private Sub Form_Load() ' opens first via AutoExec macro using Form_Load
event of a hidden form
If RefExists("ADOX") = False Then 'Load Microsoft ADO Ext. 2.x for DDL &
Security
If IsWinXP() Then
'Load a reference to the ADO Ext. 2.8 for DLL and Security
Call ReferenceFromGuid("{00000600-0000-0010-8000-00AA006D2EA4}",
2, 8)
ElseIf IsWinVista() Then
'Load a reference to the ADO Ext. 2.6 for DLL and Security
Call ReferenceFromGuid("{00000600-0000-0010-8000-00AA006D2EA4}",
6, 0)
End If
End If
End Sub
** CODE #2 **
Public Function RefExists(sLibrary As String) As Boolean
Dim Refs As References, r As Reference
Set Refs = Application.References
For Each r In Refs
If r.Name = sLibrary Then
Debug.Print r.Name, "*** Exists"
RefExists = True
Else
Debug.Print r.Name, r.Kind, r.Major, r.Minor, r.FullPath
RefExists = False
End If
Next r
End Function
** CODE #3 **
Function ReferenceFromGuid(sGuid As String, iMajor As Integer, iMinor As
Integer) As Boolean
' Usage:
'creates a reference to the ADO Ext. 2.8 for DLL and Security
' Call ReferenceFromGuid("{00000600-0000-0010-8000-00AA006D2EA4}", 2, 8)
Dim ref As Reference
On Error GoTo Error_ReferenceFromGuid
Set ref = References.AddFromGuid(sGuid, iMajor, iMinor)
ReferenceFromGuid = True
Exit_ReferenceFromGuid:
Exit Function
Error_ReferenceFromGuid:
Select Case Err.Number
Case 32813 ' Name conflicts with existing module, project or object
library. The reference is already set!
ReferenceFromGuid = True
Case Else
MsgBox ("Error # " & str(Err.Number) & " was generated by " &
Err.Source & Chr(13) & Err.Description)
ReferenceFromGuid = False
Resume Exit_ReferenceFromGuid
End Select
End Function
** CODE #4 **
Function RemoveReference(sLibrary As String)
Dim ref As Reference
Set ref = References(sLibrary) '[ACG PDF Pro Plus Mail Library]
'ADODB
References.Remove ref
End Function