add vba reference thru code

AccessProgram

Registered User.
Local time
Today, 02:45
Joined
Dec 7, 2009
Messages
68
Guys thanks for helping me out with your inputs on my other post. Can you help me again on this one.

I have this code researched that will add vba reference.

code:

Function FixUpRefs()
Dim loRef As Access.Reference
Dim intCount As Integer
Dim intX As Integer
Dim blnBroke As Boolean
Dim strPath As String

On Error Resume Next

'Count the number of references in the database
intCount = Access.References.Count

'Loop through each reference in the database
'and determine if the reference is broken.
'If it is broken, remove the Reference and add it back.
Debug.Print "----------------- References found -----------------------"
Debug.Print " reference count = "; intCount

For intX = intCount To 1 Step -1
Set loRef = Access.References(intX)
With loRef
Debug.Print " reference = "; .FullPath
blnBroke = .IsBroken
If blnBroke = True Or Err <> 0 Then
strPath = .FullPath
Debug.Print " ***** Err = "; Err; " and Broke = "; blnBroke
With Access.References
.Remove loRef
Debug.Print "path name = "; strPath
.AddFromFile strPath
End With
End If
End With
Next
'''Access.References.AddFromFile "C:\Program Files\Common Files\Microsoft Shared\DAO\dao360.dll"

Set loRef = Nothing

' Call a hidden SysCmd to automatically compile/save all modules.
Call SysCmd(504, 16483)
End Function


Function AddRefs()
Dim loRef As Access.Reference
Dim intCount As Integer
Dim intX As Integer
Dim blnBroke As Boolean
Dim strPath As String

On Error Resume Next

'Loop through each reference in the database
'Add all references
Debug.Print "----------------- Add References -----------------------"

With Access.References
.AddFromFile "C:\Program Files\Common Files\Microsoft Shared\DAO\dao360.dll"
.AddFromFile "C:\Program Files\Common Files\Microsoft Shared\VBA\VBA6\vbe6.dll"
.AddFromFile "C:\Program Files\Microsoft Office\Office\msacc9.olb"
.AddFromFile "C:\Program Files\Common Files\System\ado\msado15.dll"
.AddFromFile "C:\Program Files\Common Files\System\ado\msado25.tlb"
.AddFromFile "C:\Program Files\Common Files\System\ado\msadox.dll"
.AddFromFile "C:\WINNT\System32\stdole2.tlb"
.AddFromFile "C:\WINNT\System32\scrrun.dll"
End With

' Call a hidden SysCmd to automatically compile/save all modules.
Call SysCmd(504, 16483)
End Function

Is there any other way (code) to add vba reference? And also is there a way to properly detect bad/missing vba reference so that it can be replaced or add proper reference thru code?
 
; .FullPath

Is there any other way (code) to add vba reference? And also is there a way to properly detect bad/missing vba reference so that it can be replaced or add proper reference thru code?

You example does everything already.

To add a reference use:

.AddFromFile

to test if it is broken reference use the

.IsBroken

Where did the code come from? Did you write it?

Are you having issues with the code?
 
And I would ask - which reference are you wanting to add? It may be that you may want LATE binding which would not use a reference.
 
You example does everything already.

To add a reference use:

.AddFromFile

to test if it is broken reference use the

.IsBroken

Where did the code come from? Did you write it?

Are you having issues with the code?



I just got it thru googling because I was researching to study how codes works.
 
And I would ask - which reference are you wanting to add? It may be that you may want LATE binding which would not use a reference.


But what I want to achieve here is that when the application is started, it will check for its vba references and if some references are missing or broken, then I will use the function to correct/add the vba reference that are missing or broken.

I am not familiar late binding. Can you talk about it some here!
 
No not yet. I just researched it today. And as I have tried today, I can seem to find where is .IsBroken?

"Are you needing help understanding the code?" <------ yes please!
 
Digging up this thread, I hve an app that uses an installed OCX, however if you try to open the mdb on a machine that does not have the ocx installed you get the usual Access bootstrapping error about missing or broken references. Is there any ay on the launch of the app to test if the ocx is installed an trap it so that Access does not report the error.

The OCX in question is a webcam ocx. It's for photo badge printing and the end user my not want the version that prints photo badges. What I don't watn is to have two versions, 1 with the ocx and 1 without.
 

Users who are viewing this thread

Back
Top Bottom