Search code examples
vbams-access

Changing "Private Sub Procedure1" in Form1 to "Public -" (Form1) from Form2


In Form1 Procedure1 is private. I need to change declaration in public from Form2 with VBA.

In Form2 I'm looking for a command like that:

Private Sub Procedure2_Click ()

Form_Form1.Declaration Public

End Sub

The previous code will change From1 from

Private Sub Procedure1 ()
blablabla
End Sub

To

Public Sub Procedure1 ()
blablabla
End Sub

much appreciated


Solution

  • You can't do such a thing. The access modifiers (Private/Public) are static. When you try to call a Private Sub from another object, the code cannot be complied and thus cannot be run. Since such a code cannot be run, there is no way to create a Sub that would change a Private Sub to a Public Sub.

    Well, unless you are writing a tool as an add-in that you would call at design time. I once wrote a code formatter like this. But this code cannot be run at the run-time of your application.