PDA

View Full Version : Make an MDE through VBA



legzelda
08-01-2007, 09:18 AM
I have an interesting situation where I need to distribute a front-end MDB file that modifies a back-end MDB file by adding a new table. However, I don't want the users to have access to the MDB file after it has completed the necessary changes to the back-end. As I understand MDE files, they remove the editing code, so I can't simply distribute an MDE which will complete the updates. Is there a way to, after the updates have completed, have the MDB create an MDE of itself which users can then open? I'm trying to keep this process as automated as possible. Ideally, I would love to e-mail the updated MDB to users who run the code and have their back-end databases modified and a new MDE created.

legzelda
08-03-2007, 11:48 AM
OK, I found a way to do this.

Function GenerateMDEFile(MyPath As String)

Dim NAcc As Access.Application

Set NAcc = CreateObject("Access.Application")

'The following lines simulate accepting the default
'name, clicking Make MDE, and clicking Save
SendKeys MyPath & "{Enter}{Enter}"
SendKeys "{Enter}"

NAcc.DoCmd.RunCommand acCmdMakeMDEFile

Set NAcc = Nothing

End Function
It works great! Thanks for your thoughts and time.

legzelda
08-03-2007, 11:59 AM
Actually, my code runs, but the file is not created! :banghead: Any ideas? I get a run-time error of 2501 saying the RunCommand was canceled.