Results 1 to 4 of 4
  1. #1
    3 Star Lounger
    Join Date
    Feb 2004
    Location
    Burgas, Bulgaria
    Posts
    209
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Delete all modules in a form (Access 2000)

    Is it possible to delete all the modules in a form ? For example from the click event of one form to delete all the modules in another form.

  2. #2
    Bronze Lounger
    Join Date
    Nov 2001
    Location
    Arlington, Virginia, USA
    Posts
    1,394
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Re: Delete all modules in a form (Access 2000)

    A form can only have one code module at most. I can't think of a single good reason for deleting a form's code module from another form. If you really want to do this for some strange reason, however, here is an example:

    Private Sub DeleteFormModule(ByRef strFrm As String)

    DoCmd.OpenForm strFrm, acDesign, , , acFormPropertySettings, acHidden
    Forms(strFrm).HasModule = False
    DoCmd.Close acForm, strFrm, acSaveYes
    MsgBox "Form module deleted. Form name: " & strFrm, vbInformation, "MODULE DELETED"

    End Sub

    This sub is in the other form's code module. Call like this:

    Private Sub Command1_Click()
    DeleteFormModule "Form2"
    End Sub

    Note that 2nd form is opened (hidden) in Design view, and HasModule property set to False, which effectively deletes any existing code module. Setting this property to False programmatically will not trigger the standard warning you get when doing so in Design view interactively. It'll just delete the module w/o any fanfare. Then form closed, and changes saved, at which point the module is permanently deleted. If this is not what you have in mind, you will have to provide additional information on what this is supposed to accomplish.

    HTH

  3. #3
    3 Star Lounger
    Join Date
    Feb 2004
    Location
    Burgas, Bulgaria
    Posts
    209
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Delete all modules in a form (Access 2000)

    Thank you very much indeed. You code is superb !!!!!!!The solution you suggestes was excellent now my code flies.
    I wonder can i also delete the code within the form.I have tried the following
    OnClick

    Me.HasModule = False

    However,i get the message that this is not supported

    Best regards

  4. #4
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Delete all modules in a form (Access 2000)

    Logically, you can't run code within a form to delete the code module. Use code from outside to set the code module to false. You could do that with a function attached to the OnClick property of the command button rather than using an event procedure, but I don't understand what your purpose is in removing code modules if you use the code behind the form..
    Charlotte

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •