PDA

View Full Version : To set up a personal library?



mud2
06-09-2005, 12:20 PM
I have several Subs and Functions that I use over and over. I'd like to put them in a Library that I can refer to...same as the MANY Access functions..rand,
mid(), etc. But I don't want to mess with the registry, and when I follow the "instructions" in my Access books Nothing happens.

xCav8r
06-10-2005, 04:21 PM
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/modcore/html/deovrbuildingreusablecodelibraries.asp

Norie
06-11-2005, 05:44 AM
Why not just create a reference in Tools>References...?

xCav8r
06-11-2005, 08:26 PM
Always gotta suggest the easy way to do things. Sheesh! :tongue2:





:giggle

mud2
06-12-2005, 07:53 AM
I don't have XP Developer...references don't work (For me!) !
And Whaic 'Easy way"?

Norie
06-12-2005, 08:20 AM
I don't have XP Developer...references don't work (For me!) !
And Whaic 'Easy way"?
Neither have I.

I've just opened a test Access database and went to the VBA Editor.

I then went to Tools>References... and choose Browse...

I then navigated to another database that I knew had a load of code in it.

Voila! that code was then available in the test database.

xCav8r
06-13-2005, 07:43 PM
What Norie suggested works. Have you tried that?

mud2
06-13-2005, 09:28 PM
Does not work. Closest I get is to have my "Library' copied into my current database.
Could be that I'm working with ACCESS 2000, although I thought I was working with 2002! (or even 2003). So now I'm trying to figure out How to convert to 2002! I don't want to reload Office Pro...with attendant dangers of losing something/everything!

I've been trying Microsoft's ItemAdded Event...get almost there, then get an error message saying "File not found"
Oh well...

xCav8r
06-14-2005, 06:04 AM
Pardon the dumb question, but are you browsing to the location of your database and changing the file types to show access files? That should be working in 2000.

mud2
06-14-2005, 08:57 PM
Thanks xCav8r, for your interest;

I have two Access Db's: TryLib and Lib1.

TryLib has a form with a command buttron that calls sub "HelloWriter"

Lib1 has a Module that contains the Public Sub "HelloWriter"

While in TryLib, in the VBA project Window, Tools|References|Browse...I browse to Lib1 and select it as an Access DB. I get an error message saying that there is a name conflict. I continue and the project window shows Two DB'S, TryLib and Lib1. If I open trylib and click on the command button I get a message saying that sub HelloWriter can't be found. BUT, If I "Drag" the Module from Lib1 to Trylib, then It works.

mud2
06-14-2005, 09:22 PM
Since it sems I must copy a library file to my DB, there is a much simpler way: use the "AddFromFile" method.

The library file is called 'Hello_Goodbye.txt"
(This is copied from a vba module and saved as a text file)

While in the DB that needs the library, put in a sub..
Modules("the module name in the DB").AddFromFile "The file name including the full path to it"

I.E,
Modules("Module2").AddFromFile "C:\MyLibs\Hello_Goodbye.txt"
Now GoodBye_Hello is in module2, and accessable.

Perhaps put the sub that uses the AddFroFile method into the Form_Load event, with an incremented static "variable" that will load the file only the first time the form is loaded...Nope, won't work! This will copy the .txt file the next time the DB is opened leading top confusion amongst subs with the same name.

xCav8r
06-14-2005, 09:39 PM
While in TryLib, in the VBA project Window, Tools|References|Browse...I browse to Lib1 and select it as an Access DB. I get an error message saying that there is a name conflict. I continue and the project window shows Two DB'S, TryLib and Lib1. If I open trylib and click on the command button I get a message saying that sub HelloWriter can't be found. BUT, If I "Drag" the Module from Lib1 to Trylib, then It works.

I'm not sure what's causing the name conflict. If these are demo files, can you send them to me so I can see? Just PM for my email.

Dragging and dropping works because you're adding the module from one project to the other, but that's not the solution you've asked for. If you send me the files, I'll figure out what's causing the name conflict (generally that's caused by subs or functions with the same name), and we'll get it working so that you can link with this method suggested by Norie.

mud2
06-14-2005, 10:01 PM
I remember seeing a reference to a similar name conflict in one of my ACCESS vba books.
After I tools|reference|Browse to the Access db that I want to reference, and select it as a MDB, I get the conflict message.

The project Explorer Window shows two db's:
Access9db(TryLib) and
Access9db(Lib1)
Each with thier own "tree" of forms and modules.

The book said that you cannot have two db's open at one time.

I'll send you the files Access db's if you explain what "PM" your address means.

xCav8r
06-14-2005, 10:33 PM
PM = Private Message

Sorry, didn't mean to be arcane.