If you open Microsoft Access, then open the visual basic window so you can see the list of modules and code in your Access project. You can drag a text-based file (txt, cls, bas, etc) from windows explorer and drop it into your module folder.
This drag and drop action will import the code in the text-based file into your project and prompt you to save it (with the default name being the name of the file you dropped.
Is there a way to do this programmatically using VBA? It seems like a simple task that should have a simple solution, but I've been researching for days and can't seem to find a simple way to do it.
You can use the
VBComponents.Import
method from the VBE object model. See the Import Method (VBA Add-In Object Model) topic in Access' help system for details.This sample code imported modImportMe.bas from the folder where my database is stored.
Note this database actually contains only one
VBProject
, so I could have referenced it withVBE.ActiveVBProject
. However if yours includes more than oneVBProject
, it's safer to refer to it by name, andVBProjects("<Name>")
should work even when there is only one.Yes, that's the command
LoadFromText
to use.Usage: