Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Add References using VBA 12

Status
Not open for further replies.

rgbanse

MIS
Jun 4, 2001
211
US
Is the a way to add references (ie; Microsoft Scripting Runtime) to a Database using VBA.
thx
RGB
 
Provided you've referenced the Microsoft Visual Basic for Application Extensibility you may play with the References collection of the VBProject object.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
I'm importing a form and its supporting code to a new database. The form and code require a reference to 'Microsoft Scripting Runtime' so I open the dialog box and 'CheckMark' the reference. Is there a way to do this using VBA within a module.
thx
RGB
 
Have you read my previous post ?
I admit I omit to talk about the F1 key...

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
I'm missing something here. I have not referenced Microsoft Visual Basic for Application Extensibility.
What I'm wanting to do is to create a module that I would import into every new database.
This module would import Links, forms and other code.
Part of this code would be to create references as stated above. The code to create these references is where I am hoping to get some help.
thx
RGB
 
Maybe these examples will help you.


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
 
It certainly helped ME! Just what I was looking for. Thanks, and have a star!
 
Ditto! on the stars! You just shaved about 5 days off my program!
 
After all those people who understand this so well, here comes the fool.

Can someone give me an idiots guide on how to incorporate this.

So far I've copied the code into a module and have a couple of buttons on a form to run the two functions. However, I get an unexpected error '40230'.

I know it's due to my lack of understanding that I can't get this to work for me and would therefore be grateful for some guidance.

For info and in case it makes any odds, I’ll be running the app as an MDE in ART.

Ta.
 
Please ignore my last post. I imported all into a new DB and it's now working like a dream. Must have been some corruption in the works.

The star is yours.
 
This has helpled me tremendously, thanks for sharing. Another star for your collection, cmmrfrds.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top