Link to home
Start Free TrialLog in
Avatar of Andy Brown
Andy BrownFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Moving a .BAS file into an external database

I need to create a .BAS file which is pushed into an external Access .mdb file.  Any suggestions?
Avatar of datAdrenaline
datAdrenaline
Flag of United States of America image

Are your trying to take a module from one db and make a copy of it into another db?
Avatar of DatabaseMX (Joe Anderson - Former Microsoft Access MVP)
If you open up a given module ... then File>>Export File ...

the Windows dialog box comes up ... and the SaveAs is already set to .BAS

mx
Avatar of Andy Brown

ASKER

Thanks guys.  

I create the VBA on the fly as it is to do with a security feature.  Historically, I have created the.BAS file, imported it into the open database (running the function) and then exported it to the destination.  When I run this function it may upgrade 40+ databases (all with different VBA scripts) and it seems to be really slow.

If I could send the .BAS file into the destination .mdb database, i'm sure it would speed things up.
Well, on the flip side ... you can then Import that .bas file into the other mdb.  Not sure how this can be automated, which is what you are after, right ?

mx
Does this .bas file change over time, or is it static? If it's static, you could just include a module that created your module - although I'm not sure how well that would work.

You could also use Application.LoadFromText(acModule, "YourModuleName", "full path to the module.txt file")

Note that LoadFromText expects the incoming file to be in a specific format, so be aware of that.
Hi, unfortunately it isn't static, which is why i dont want to keep deleting and importing .BAS files to the main system.

I'm going to give the Application.LoadFromText function a try in the morning - that might work.

I'll keep you posted and come back to you.

Thanks as always.
From the host database, you can use the DoCmd.TransferDatabase method ...

Public Sub FooBar(strModule As String, strDestinationDB As String)

    DoCmd.TransferDatabase acExport, "Microsoft Access", strDestinationDB, _
            acModule, strModule, strModule

End Sub


ASKER CERTIFIED SOLUTION
Avatar of datAdrenaline
datAdrenaline
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
This solution worked beautifully.

Nice work everyone - thank you.