Why Doesn't this work

PaulJL

New Member
Joined
Oct 9, 2002
Messages
48
I am currently looking at training manual and have been asked to enter the following code as a module.

Sub PrintRecords()
Dim DBCURR As Database
Set DBCURR = CurrentDb
Debug.Print DBCURR.Name
End Sub

But when i try and test it in the debug/Immediate Window all i get is an error message

"Can't find project or library".

I have looked at the Access help but it gives a similar set of code which i copied in and tried to test and that came up with the same error. What am i doing wrong?
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Are you using Access 2000? If so, then Database and CurrentDB are implied. If you are looking to use DAO rather than ADO, set a reference to DAO in your References.
 
Upvote 0
dao

try:
________________________________________________________
Sub printrecords()

On Error Resume Next

Application.References.AddFromGuid "{00025E01-0000-0000-C000-000000000046}", 5, 0

Call debugger

End Sub
________________________________________________________
Sub debugger()

Dim DBCURR As Database
Set DBCURR = CurrentDb
Debug.Print DBCURR.Name

End Sub
________________________________________________________

You have to start with the sub printrecords(), to add the dao ref. If you try to dim DBCURR as a database before you've added the dao ref, it'll bug up.

edit: This reference should only need to be added once, not everytime you run your code...

edit: thanks to dk for the lib ID

HTH,
 
Upvote 0
Corticus, on a related topic, do you know how to register an ActiveX control at run-time? I have a Rich Text File control in my project which needs to be registered on every user's computer before they can use it. I'd like to see this process automated.
 
Upvote 0
Actually Dugantrain,

I'm looking for a list of ALL the references and their related IDs. You should be able to add all of them programatically using the above method, I just don't know the IDs of any but the one I use a lot. I found a plugin somewhere that will tell all the libraries your current project is referencing, and their ID#s, but that doesn't do you much good since you don't really need the ID# unless you're trying to add a reference, in which case it won't be there.

I'll post back if I have any luck looking for this list, and I'll also check on that ActiveX reference...

HTH,
 
Upvote 0
Okay,

I found some code that gives you the file locations of your different references:

Code:
Function ReferenceInfo()

   Dim strMessage As String
   Dim strTitle As String
   Dim refItem As Reference
   
   On Error Resume Next
   
   For Each refItem In References
      If refItem.IsBroken Then
         strMessage = "Missing Reference:" & vbCrLf & refItem.FullPath
      Else
         strMessage = "Reference: " & refItem.Name & vbCrLf _
            & "Location: " & refItem.FullPath & vbCrLf
      End If
      Debug.Print strMessage
   Next refItem

End Function

Type in ReferenceInfo in the immediate window

I think you can then use the addfromfile method (I can't find a **** list of GUIDs for anything) to add the reference:

Syntax

Set object = References.AddFromFile(filename)

The AddFromFile method has the following arguments.

Argument Description

object A Reference object.

filename A string expression that evaluates to the full path and file name of the file containing the type library to which you wish to set a reference.

check this out for more:

http://msdn.microsoft.com/library/d...ry/en-us/off2000/html/acmthCreateFromFile.asp

I REALLY want a list of the different GUIDs, so I can add them programatically without searching for 6 freaking hours to find each one, but I can't find anything anywhere, except to list the refs you already have made.

HTH,
 
Upvote 0
Okay,

Here's one for activex plugins.

File location:
C:\WINNT\System32\plugin.ocx

Code to add reference:
Code:
Sub addactivex()

On Error Resume Next

Application.References.AddFromFile ("C:\WINNT\System32\plugin.ocx")

End Sub

Here's the file locations of the different directx references you migh need, just replace the file name in the above code with the one you're interested in...

Microsoft ActiveX Data Objects (multi-dimensional) 2.5
C:\Program Files\Common Files\System\ado\msadomd.dll

Microsoft ActiveX Data Objects 2.0 Library
C:\Program Files\Common Files\System\ado\msado20.tlb

Microsoft ActiveX Data Objects 2.1 Library
C:\Program Files\Common Files\System\ado\msado21.tlb

Microsoft ActiveX Data Objects 2.5 Library
C:\Program Files\Common Files\System\ado\msado15.dll

Microsoft ActiveX Data Objects Recordset 2.5 Library
C:\Program Files\Common Files\System\ado\msador15.dll

and just for reference, the DAO 3.6 lib (the original requested reference) is located at:
C:\Program Files\Common Files\Microsoft Shared\DAO\dao360.dll
and could be added using:
Application.References.AddFromFile ("C:\Program Files\Common Files\Microsoft Shared\DAO\dao360.dll")

This actually seems like a reasonable way to add any reference. You don't have to use the code above to determine the locations of any references called, you can just select tools|references, check the one you want, and it will tell you the file location. You can then add that file location to the 'addfromfile' code, and you should be good to go. My 'on error resume next' is just a sloppy way to keep you from trying to add the same reference twice, I suppose you could test to see if it is added, and if so, don't try to add again, but my way seems to do the job.

I am happy.

HTH,
 
Upvote 0
PaulJL said:
Thanks!!!

What is the ADO version of the code that i was trying to use?

Regards

Did you ever get the answer to this? If not,

Code:
Sub PrintRecords()
    Debug.Print CurrentProject.FullName
End Sub
or
Code:
Sub PrintRecords2()
    Dim objCP As CurrentProject
    
    Set objCP = Application.CurrentProject
    Debug.Print objCP.FullName
End Sub
If you want to leave it similar to the current form, you'll need to add a reference to the "Microsoft DAO X.x Object Library" by going to Tools-References from inside the VBE (find the reference, then check the box next to it). Then your original code should work.

HTH,

Russell
 
Upvote 0

Forum statistics

Threads
1,221,517
Messages
6,160,260
Members
451,635
Latest member
nithchun

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top