We help IT Professionals succeed at work.

Save Modules in ms access

Svgmassive
Svgmassive asked
on
Is there a way to save all changes to he modules via a command button etc. in ms access.
Comment
Watch Question

Daniel PineaultPresident / Owner CARDA Consultants Inc.
Distinguished Expert 2018

Commented:
What about
DoCmd.Save

Open in new window

Doesn't that only work on the active object? Not that I have a better solution. That said, Ctrl-S should save the entire database and all modules.

Daniel PineaultPresident / Owner CARDA Consultants Inc.
Distinguished Expert 2018

Commented:
Doesn't that only work on the active object?
When I tested, it appeared to save everything.


Hey Anders, since you're here, any clue what
DoCmd.RunCommand acCmdSaveAllModules

Open in new window

does?  I've tried using it thinking it would be perfect for this, yet I can't get it to work?!

Strangely, the following works
DoCmd.RunCommand acCmdCompileAndSaveAllModules

Open in new window

So compiling seems required?  I'm confused.

I suppose its possible that Docmd.Save works in the same way as hitting save, i.e. saving ALL active objects and not just the Active object. I really haven't looked into it.


And sorry, this is the first time I've heard of   acCmdSaveAllModules or acCmdCompileAndSaveAllModules

Scott McDaniel (EE MVE )Infotrakker Software
Most Valuable Expert 2012
Top Expert 2014

Commented:

A better question is: Why do you need a button save changes to Modules? A button would show on a Form, and if you're viewing a Form in Form view, you shouldn't be editing a module.



Fabrice LambertConsulting
Distinguished Expert 2017

Commented:
If youre looking for a quick way to save all the changes you've made in the code, afraid you're looking at the wrong way, because:
- It will require executing something, so your code "for saving" will have to compile and be bug-free first, wich defeat the purpose of the desired functionality.
- Ctrl-S shortcut is much faster.
- As a developper, Ctrl-S should be a reflex.
President / Owner
Fellow 2019
Most Valuable Expert 2017
Commented:
Code does not need to be complied in order to be saved and I could see where you would need something like this if you were doing something like an  add-in.

 You can use those commands while a module is open and selected, or you can run through the containers collections.   i.e.

'***************** Code Start *******************
' This code was originally written by Dev Ashish.
' It is not to be altered or distributed,
' except as part of an application.
' You are free to use it in any application,
' provided the copyright notice is left unchanged.

Function fCompileProject() As Boolean

  Dim db As Database
  Dim ctr As Container

  If Not Application.IsCompiled Then
    Set db = CurrentDb
    Set ctr = db.Containers!Modules
    If ctr.Documents.Count > 0 Then
      DoCmd.OpenModule ctr.Documents(0).Name
      DoCmd.RunCommand acCmdCompileAndSaveAllModules
      DoCmd.Close acModule, ctr.Documents(0).Name
    Else
      'No Modules present, try Forms container
      Set ctr = db.Containers!Forms
      'no need to check for count since this code itself must be present *somewhere*
      With ctr.Documents(0)
        DoCmd.OpenForm .Name, acDesign
        DoCmd.RunCommand acCmdViewCode
        DoCmd.RunCommand acCmdCompileAndSaveAllModules
        DoCmd.Close acForm, .Name
      End With
    End If
  End If
  fCompileProject = Application.IsCompiled

End Function

'****************** Code End ********************

Open in new window


 There used to be a hidden syscmd call to compile a project as well, but I don't know if it still works or not:

SysCmd(504, <flag>)

 Where flag =

 16481 - Unknown
 16482 - Unknown
 16483 - Save VBA with compiled code
 16484 - Save VBA without compiled code

Jim.