Hi, I have a bas file and I want to import it into 150 databases. I have been trying to find a way to do this in VBA and not come up with anything. Does anyone know how to do this?
you need a way to loop through all of the databases you want to open. i don't know if you would need to open them or not, but if you do, make sure you open them and set the focus to them. then, each time through your loop, use this code to get the module:
Code:
Dim Acc As Access.Application
Acc.OpenCurrentDatabase "FULL PATH OF DB TO OPEN AND IMPORT TO"
Application.VBE.ActiveVBProject.VBComponents.Import "PATH OF THE .bas FILE"
DoCmd.Save acModule, "NAME OF THE .bas FILE"
I have found that whenever you import a .bas file, it is also very, very important to manually compile the VBA code before you close the database. Depending on what version of Access you are using, it is possible to corrupt ALL the VBA code in a database if you do not do the compile before you exit the database.
I would also make sure you have a good backup of the database before you import the .bas file.