Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 618
  • Last Modified:

I need a command to save and publish a db as an accde via vba.

I posted this before, but I was hoping someone might have some new ideas.

I need a command to save and publish a db as an accde via vba.

Any thoughts?
0
akivashapiro
Asked:
akivashapiro
  • 4
  • 3
1 Solution
 
Jim Dettman (Microsoft MVP/ EE MVE)PresidentCommented:
You can try:

SysCmd 603, strPathInputMdb, strPathOutputMde

However it cannot be the current MDB.

Jim.
0
 
peter57rCommented:
DO you mean you're trying to create an accde from the database you're currently in?
I don't think that is possible.

It is possible to create an mde of a different database in code.
0
 
akivashapiroAuthor Commented:
Sorry for the long delay.

I'm using MS Access 2010.

I create a new database and I tried

  SysCmd 603, strPathInputMdb, strPathOutputMde

It does nothing. Also, 603 is not a value listed for SysCmd in the help or drop down enumerations. It may be a hidden command, but it does nothing and generates no error.

I then tried creating a new application instance:

  Dim appAccess As New Access.Application
   appAccess.OpenCurrentDatabase sourceDB$ 'where sourceDB is a different DB from the currentDb
  appAccess.RunCommand acCmdMakeMDEFile

This returns the same error message as when trying to execute acCmdMakeMDEFile on the current db.

Both of you suggest that what I want to do can be accomplished - albeit in a differrent db. If you could attach some code you've tested that would be great and appreciated.

Thanks!
0
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

 
Jim Dettman (Microsoft MVP/ EE MVE)PresidentCommented:
<<It does nothing. Also, 603 is not a value listed for SysCmd in the help or drop down enumerations. It may be a hidden command, but it does nothing and generates no error.>>

 603 is an undocumented call that worked in earlier versions

<<I then tried creating a new application instance:

  Dim appAccess As New Access.Application
>>

  That approach would work, but you don't want to open the database.

Try this instead:

Function GenerateMDEFile(MyPath As String)

    On Error GoTo FailedMDE
   
    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
   
    Goto Done

FailedMDE:
    msgbox "Failed" & vbcrlf & err.description
Done:
    On Error Resume Next
    Set NAcc = Nothing

End Function


  Note the DB is not opened.  This should work as it is a solution posted by Rocki Roads here on EE.  

  However, I don't know that I'd be trying to automate MDE creation; it's so problematic.   A MDB must be fully compiled, compacted and repaired, and be free from errors in order to convert to a MDE.

  I typically create a brand new DB, import everything, check references, then compile, and follow with a C&R before trying to make a MDE.

  Many in the past have tried to automate that whole process and without much luck (it's simply easier to do it manually).

Jim.
0
 
akivashapiroAuthor Commented:
Thanks Jim for the response.

-> In order to do this:
    'The following lines simulate accepting the default
    'name, clicking Make MDE, and clicking Save
    SendKeys MyPath & "{Enter}{Enter}"
    SendKeys "{Enter}"

-> There must be a dialog box to accept the input.

-> This line does not generate a dialog box in Access 2010. I think it did in 2003.
    Set NAcc = CreateObject("Access.Application")

Any other ideas?

Thanks.
0
 
Jim Dettman (Microsoft MVP/ EE MVE)PresidentCommented:
<<Any other ideas?>>

 SendKey's sequence is a bit different.  You need Alt/F, then O to bring up the open file dialog.  

  But the other thing that trips this up is the "Enable content" button.  This method is too fragile and the wrong approach.

  Let me see what I can come up with.

Jim.
0
 
Jim Dettman (Microsoft MVP/ EE MVE)PresidentCommented:
I'm afraid I've come up with not much.  Best you can do is put the DB in a trusted location and use the sendkey's approach and I have verified that the syscmd 603 call does not work beyond 2003.

Honestly, the MDE creation process is so problematic, I'm not sure why you'd want to automate it anyway.

Jim.
0
 
akivashapiroAuthor Commented:
Okay, thanks for trying.
0

Featured Post

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now