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

Auto add Reference when Access opens 1

Status
Not open for further replies.

thegameoflife

Programmer
Dec 5, 2001
206
US
Is there a way to add a reference when I start a new Access DB?
 
The usual way is to be in some vba code and go up to the menu and select Tools then references. At this point, you can add any reference you need.
 
Yes, there is:

Dim strPath$
strPath = "C:\Path\FileName.dll" 'or whatever
References.AddFromFile strPath

But you have to make sure that the reference does not exist before adding it.


[pipe]
Daniel Vlas
Systems Consultant
danvlas@yahoo.com
 
Is there a way to code it into Access so going forward it's already in my list of reference for all new databases that are opened. I know how to set them after the DB is open, I was looking for a way to avoid that one small step.
 
danvlas,

Do you know how to check for the reference as well. BTW, thanks alot for your post on one of my threads as well. I had a question for you on it if you get time maybe you can look into it.
 
Here are a couple of functions that work together. You need to know the path and file name.

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
'- repeat for the other references you need.

End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top