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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Set a reference programatically 3

Status
Not open for further replies.

storm75m

Programmer
Apr 18, 2001
81
US
Is it possible to set a reference to a library programatically? I have about 100 databases that I need to update with new code, and I need to set a reference to the Microsoft Active Data Objects 2.5 library in each one. When I usually update the databases I have one database that I use to copy objects such as forms or modules and I usually use the TransferDatabase method. I've just never had to set a reference before. Can anyone help with this? Thanks in advance...
 
I haven't actually tried it, but according to this thread ( it is possible.

Dim ref as Reference
Dim db as Database
Dim qd as QueryDef

Set db = CurrentDb
Set qd = db.QueryDefs("qryReferences")
For Each ref In References
If ref.IsBroken Then
qd.Parameters("n") = ref.Name
Set rs = qd.OpenRecordset(dbOpenDynaset)
Access.References.AddFromGuid rs!Guid, rs!Major, rs!Minor
End If
Next ref
 
Here is the basic idea, modify as needed.


Function ReferenceFromFile(strFileName As String) As Boolean
Dim ref As Reference

On Error GoTo Error_ReferenceFromFile
Set ref = References.AddFromFile(strFileName)
ReferenceFromFile = True

Exit_ReferenceFromFile:
Exit Function

Error_ReferenceFromFile:
MsgBox Err & ": " & Err.description
ReferenceFromFile = False
Resume Exit_ReferenceFromFile
End Function

Function CreateReference()
If ReferenceFromFile("C:\Program Files\Common Files\SYSTEM\ADO\msadox.dll") = True Then
MsgBox "Reference set successfully."
Else
MsgBox "Reference not set successfully."
End If
End Function

 
This works fine for the current database, but is there a way to automate and set the reference in another database? I have to loop through a list of databases to update the code in each one.
 
Why not give Kotaro's solution a try; however substitute a different database for currentDb.

E.G.
dim MyDb as database
set MyDb = DAO.OpenDatabase(<pathname>)
 
Well there are a couple of problems with the first suggestion. The line that reads &quot;For each ref in References&quot; refers to the references for the current database. There is no references collection for the database object. The only thing that the db object in that code is used for is to read the qryReferences table. The references collection belongs to the &quot;Access&quot; object. So if I can only find a way to read the references for a different database I think I have enough code samples here to make it work. Thanks guys...
 
'Access.References'

My bad. OK, to get a handle on that you'll have to use automation to open another copy of Access, something like:

Dim AccApp As Access.Application

Set AccApp = CreateObject(&quot;Access.Application.8&quot;)
AccApp.OpenCurrentDatabase FilenameAndPath$

then you'll be able to use AccApp.References as above.

P.S. - (&quot;Access.Application.8&quot;) stands for Access '97. Access 2000 will be (&quot;Access.Application.10&quot;). (You can find out which version of Access is running on your PC by peeking in the registry (link thread329-543812).

 
Alright, that looks good, let me give it a shot, thanks a lot!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top