If anything is marked as missing:
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.
- Do you actually need that Reference in your project? If not, simply remove the checkmark and click OK.
If you are not sure then make a note of the full name and path of the reference (you may need to find it later), then remove the checkmark and click 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, mark the checkbox for the other version, un-mark the "Missing" one, then click 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.
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 reopen 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!)
- The last potential solution is to specify the library for the functions/methods which generate the error.
While this looks the easiest at first glance, it has been listed 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:
MsgBox VBA.Trim("my text")
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.