"Compile Error: Can't Find Project or Library"
What it means:
You are trying to use a sub/function which is declared in an external file (via "Project"->"References"), but for some reason that file cannot be found.
Unfortunately it is also possible for this error to occur in odd places (particularly on standard functions like Mid/Trim/Date/Format) if any of the References you have selected is not valid.
How to solve it:
First of all, as recommended in the Help for this error, check your References (via "Project"->"References") to see if any of the ticked items (which are all at the top of the list) start with "MISSING:", as shown in this picture:

If anything is marked as "MISSING":
If there is a Missing Reference, you should consider it vital to fix it - the other methods shown later will only temporarily hide the error (thus still requiring fixing the reference later), and will also be likely to take
much more effort than the fix itself.
No matter which line of code the error occurred on, the item(s) marked as "Missing:" is actually the Project/Library which can't be found.
Side note: The likely reason for this error occurring on apparently unrelated lines of code (like Mid/Trim/etc) is that the same sub/function name can be used in multiple Projects/Libraries. For example you could have two references that each have a function called "Foo", or to be awkward (and clash with the built-in function) "Trim".
As a Project/Library is missing, the compiler cannot tell if it contains a sub/function with the same name (which may have been the one you intended), so rather than use what might be the wrong one, it gives the error at that point.
It is possible to stop the error occurring on the wrong lines of code (using the method at the end of this post), but that can be extremely time consuming, and you will probably not be able to actually compile your project until you have corrected this problem.
To fix a "Missing" Reference, do one of the following:
- Do you actually need that Reference in your project? If not, simply remove the tick and press OK.
If you aren't sure.. make a note of the full name and path of the reference (you may need to find it later!), then remove the tick and press OK. Press ctrl-F5 to start your app with a full compile, and if you do need the reference, you will get a different error (perhaps "user defined type not defined") at the point where you use it. If that happens, you will need to perform one of the following steps.
- Is there another version that doesn't start with Missing you could use instead? (eg: if you have "MISSING: MyApp 2.1", do you also have "MyApp 2.2"?)
If so, tick the other version, un-tick the "Missing" one, then press OK.
Note that if the version is different, it may work in a different way, so this solution is not always appropriate - you may need to install a certain version (if so, see the next step).
- If there isn't another version (or you need a particular version) the solution is to install that item to your computer, but how you do this depends on what the item is.
- If you got the project from another developer, ask them to create an installation package (and then run it on your computer), as that will install the required file(s).
- If you know which company created the item (eg: "Microsoft ActiveX Data Objects 2.7 Library"), search their web site to see if there is an installation package for it (in this case there is, MDAC 2.7).
- Otherwise, post a new thread on the forums, and we will hopefully be able to help you find it.
Repeat this process for each item that was labeled as "Missing: ", and then run the program again - this error should now be resolved.
If there are no missing references, or you still get the error after fixing them, here are some alternatives that have been suggested on the forums:
- Have you had this project open for a long time (and run it several times) without the error occurring? If so, simply close VB (saving your files first if apt) and re-open it - the project is likely to work again.
- The next option is to re-create the project file.
To do that:
- Open VB again (leaving your current project open, as you will need to see it in the next steps).
- Create a new project of the same kind (eg: "Standard Exe").
- Go to "Project"->"References", and tick the same items which are ticked in your original project.
- Do the same for "Project"->"Components". Note that the ticked items are not always shown at the top of this list, so you may want to click "Selected Items Only".
- Remove the files that were added to the new project by default (such as "Form1"), by right-clicking on them in the Project Explorer window (or use the Project menu).
- Add all of the files from your previous project (forms/modules/etc), by right-clicking in the Project Explorer and selecting "Add" (or use the Project menu).
- Go to "Project"->"Properties", and set the same "Startup object" (and copy any other properties you want).
- Save the Project to a new file (do not overwrite the original!)
You can now try to run this project, and hopefully it will not give the error. If it works, you can delete or rename the orignal project file (*.vbp), and use the new one instead.
- The last potential solution I am aware of is to specify the library for the functions/methods which generate the error.
While this looks the easiest at first glance, I have saved it until last as the total amount of work involved is typically
much higher than all of the others (and in many cases it is just a temporary fix, still needing one of the solutions above, or a repeat of this each time you add more code).
For standard built-in functions like Mid/Trim/Date/Format, the library is VBA, so for those you would specify the library like this:
Code:
MsgBox VBA.Trim("my text")
To find what library a function/method is in, go to the Object Browser (press F2, or use the "View" menu), and in the second box (next to the binoculars) type in the name of the function/method, then press Enter. Look for the function/method name in the "Member" column, and simply copy what is in the "Library" column.
The amount of work for this method is fairly small for each line of code, but the time can build up dramatically if you need to do it for multiple lines - which is likely to be the case.