Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Copying Modules

Status
Not open for further replies.

NewfieGolfer

Technical User
Mar 29, 2001
80
0
0
CA
Hi,
I'm trying to copy modules from one database to another database. The problem i'm having is that i'm getting that nasty "Error accessing file" message when i try and open the modules after copying them. I'm doing the copying using VBA (I need to copy using VBA). I know that in order to get rid of that message i need to copy to the other database, open the modules in the other database, compile them, save and then close the other database. How would i do this using VBA?

Thanks,
NG
 
That's what i need help with. I need to make that reference but i can't do it with VBA since when you copy anything with code, it messes up the database u copy to, unless you open the database, compile the code, etc (excellent perk of A2k). The reference to DB3 must be created when the db2 is created using the main database.

Main database creates db2, and then creates reference within db2 to db3(Modules Database)

NG
 

Sorry it took a while to get back to you.

So it looks like you want to add a reference using code, and you certainly have a reason to want to do it, so the function below should do it for you. Of course, I have to give the always present proviso, and that is this is A97 code, but it should work, I hope, with A2K as well, but no guarantees.

Function ReferenceFromFile(strFileName As String, Optional Warning As
Boolean) As Boolean
Dim ref As Reference

On Error GoTo Error_ReferenceFromFile
Set ref = References.AddFromFile(strFileName)
ReferenceFromFile = True

Exit_ReferenceFromFile:
Exit Function

Error_ReferenceFromFile:
If Warning = True Then msgbox Err & ": " & Err.Description
ReferenceFromFile = False
Resume Exit_ReferenceFromFile
End Function

The above code works Access '97 all service packs, on NT4 and all service
packs
Robert Berman
Data Base consultant
Vulcan Software Services
thornmastr@yahoo.com
 
I went back and read my thread and it was a very ambiguous statement and i'm sorry for that. What i meant to say is that i need to make a reference without using VBA. So i need it in the event procedures as an expression or macro or something, but not VBA. Sorry again. So, as an expression i can't put "=def()" because i haven't referenced the database. So in that expression i need to reference the modules database?

I thought this was gonna be so easy, copy the modules and reference em, but that stupid Access 2k error is makin this a pain.

NG
 
I finally got it to work!!!!

Here's what i did, this code is run from my main database:

file2 = "c:\FormsDB.mdb"
modulefile = "c:\modules.mdb"

Set AppAccess = New Access.Application
AppAccess.OpenCurrentDatabase file2

AppAccess.DoCmd.TransferDatabase acImport, "Microsoft _
Access", modulefile, acModule, "TestCode", "TestCode"
'I just repeated this for all my modules.

AppAccess.DoCmd.OpenModule "TestCode"

AppAccess.DoCmd.RunCommand acCmdCompileAllModules

AppAccess.CloseCurrentDatabase

This code will copy the modules over to my forms database from the modules database. Now i can run my procedures from the forms database.

Thanks for all the help. It's greatly appreciated. I've actually learned a great deal from this thread alone.

Thanks again,
NG
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top