Loading DAO at run time....

everblue

Registered User.
Local time
Today, 06:59
Joined
Jul 20, 2002
Messages
21
Hi experts,

I am using a bit of VB code in my form and that needs to have DAO references loaded first.
I needed to run the same code in another database, and it generated error, coz DAO was not loaded there.

What I need is to have a VB code to load DAO at run time if i need to run this form in any database.

Thanx
 
It sounds like the second database may not have a reference to the DAO library. Ordinarily, you can just use DAO objects in your code as long as that reference is set. In the second database, open any code module, then select Tools, References, and make sure the correct DAO library is checked.
 
Try this.

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

Sub CreateCalendarReference()
If ReferenceFromFile("C:\Program Files\Common Files\Microsoft Shared\DAO\dao360.dll") = True Then
MsgBox "Reference set successfully."
Else
MsgBox "Reference not set successfully."
End If
End Sub

You may supply the dao360.dll with your application, then just refer to the dll based on the app. path.
 
Same DAO....

Hello Dear Tim,

Thanx for the code, it works perfectly, except one thing. I put the code from CreateCalenderReference() into Form_Load() procedure, it works fine for the first time, but if I next time load the form, it says Name conflict. that's coz it loads the same file again and it creates conflict. Isn't there a way to check if the reference is already loaded, just ignore, if not then load that.

Waiting for ur reply...
 
Change the code in this part showed below.

...
Error_ReferenceFromFile:
If Err = 32813 Then
' All set
Exit Function
ElseIf Err = 48 Then
MsgBox "DLL is not found", vbOKOnly, "Missing DAO DLL"
Exit Function
Else
MsgBox Err & ": " & Err.Description
ReferenceFromFile = False
Resume Exit_ReferenceFromFile
End If
End Function
...
 
Tim,

I am trying to use your code but I am not able to set the reference. I am not getting any errors. Here is how I am trying to set my reference...

Private Sub bSetReference_Click()
ReferenceFromFile ("C:\Program Files\Common Files\Microsoft Shared\DAO\dao360.dll")
End Sub

What am I doing wrong. Thanks!
 
Since my last post has suppressed the error message (If Err = 32813 Then ...), so you don't see the message. You can check if it works or not by remove the DAO from the References. Then click the button, you'll find DAO is set.
 
Tim,

I think Access 97 is confusing DAO360 with DAO351. Is this possible?

The only DAO reference I have is "Microsoft DAO 3.51 Object Library". I am using Access 97 with Windows XP.

After I removed my reference to DAO351, your code worked and added the reference to DAO360!!!

But, when I check the reference with your CreateCalendarReference() sub, I get the error message "32813 Name Conflick..."

Here is how I am using your CreateCalendarReference sub to test the reference...

Sub CreateDLLReference()
If ReferenceFromFile("C:\Program Files\Common Files\Microsoft Shared\DAO\dao360.dll") = True Then
MsgBox "Reference set successfully."
Else
MsgBox "Reference not set successfully."
End If
End Sub

Can you spot what I am doing wrong to verify my DAO reference?

Any ideas why Access 97 thinks the reference to DAO360 already exists when I only have a reference to DAO351?

Thanks!
 
They both have the same name in References, DAO.

Try the code below.

Sub ShowRefName()
Dim Ref As Reference
For Each Ref In References
Debug.Print Ref.FullPath & " --> Name:= " & Ref.Name
Next
End Sub

Or check for DAO if loaded with this.

Sub CheckIfDAOLoaded()
Dim Ref As Reference
For Each Ref In References
If Ref.Name = "DAO" Then
MsgBox "DAO Ref exists"
Exit Sub
End If
Next
End Sub

Check the References for more detail in Help, if you want to master the References.
 

Users who are viewing this thread

Back
Top Bottom