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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Export Module from .MDE of VB Protected .MDB

Status
Not open for further replies.

DaOtH

Technical User
Jan 22, 2002
114
SE
All,

I am trying to export a module to a Code created database.
All works well, but i really want to have my original db as an MDE (Or at least a MDB with a password on the VB code).

When trying this, i found out that exporting a module from an MDE (or VB code protected MDB) is not possible.

ANy idea's how to tackle this ?
Would it be an option to create an .bas file from code and then import it in the new database ?. How would one do that and how would i create/import a macro ?

Any help is appreciated.

"In three words I can sum up everything I've learned about life: it goes on."
- Robert Frost 1874-1963
 
The point of VBA modules is that all the code in them is compiled and cannot be edited or viewed or exported, so that is definately out of the question, however, there is an undocumented SaveAsText statement that you may be able use to do this in the VB protected code. I've not tested it with pasword protection, but it's worth a try. Open the Immediate Window (Ctrl+G), and enter:
SaveAsText
The Intellisense should guide you through the arguments. This can be used on any object in the database and the objects can be reloaded using the LoadFromText statement.

Let me know if this works.


B


----------------------------------------------
Ben O'Hara

"Where are all the stupid people from...
...And how'd they get so dumb?"
NoFX-The Decline
----------------------------------------------
 
Thanx for the tip.
Unfortunately SaveAsText from an VB Protected Db gave me an 'Reserved Error' but you pointed me in the right direction anyway.

Managed to create text files from my VB protected DB.
And then managed to import this textfile in the second database, which, luckily doesn't need to be an .MDE or VB Protected. (most likely this will work from an .MDE as well, havent tried yet).

Just for your interest, below the code :

Option Compare Database
Option Explicit

Public Function Export()
Dim fsFile, tsFile As Object
Dim dbCurrent As Database

Set dbCurrent = CurrentDb
Set fsFile = CreateObject("Scripting.FileSystemObject")
Set tsFile = fsFile.CreateTextFile("C:\module.bas", True)

tsFile.WriteLine ("Option Compare Database")
tsFile.WriteLine ("Public Function test()")
tsFile.WriteLine (" Msgbox ""Test"" ")
tsFile.WriteLine ("End Function")
tsFile.Close
End Function

Public Function Import()
Dim appAccess As Access.Application

Set appAccess = CreateObject("Access.Application")

appAccess.OpenCurrentDatabase ("C:\db1.mdb")
appAccess.LoadFromText acModule, "Module", "C:\module.bas"
appAccess.CloseCurrentDatabase
End Function

"In three words I can sum up everything I've learned about life: it goes on."
- Robert Frost 1874-1963
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top