mkc
mkc

Reputation: 41

Open VBA code of active form

I have an Access database with a huge amount of forms (300+) and VBA code. The backend of this Access db is in MS SQL.

When I am on a control in a form (in formview), I want to "jump" directly to the VBA code of this form without closing or putting the form in design mode. I can do this with a shortcut key which I assign to a function.

This works well when the control is not in a subform. But when this is the case, the code runs into an error telling me that the module of form cannot be found.

This is the code i use:

Dim sFrmName As String

sFrmName = Screen.ActiveControl.Parent.Name
If Nz(sFrmName, "") = "" Then Exit Function

'Open forms module
DoCmd.OpenModule "Form_" & sFrmName

How can i change this code so that i dont have to put the form in design mode to go to the VBA code of this form, which will also work for subforms? I know I can do this manually in VBE, but I'd like to do it in VBA.

Upvotes: 2

Views: 2371

Answers (1)

mkc
mkc

Reputation: 41

Found one way to do it, this also works for subforms:

Dim sFrmName As String

sFrmName = Screen.ActiveControl.Parent.Name
If Nz(sFrmName, "") = "" Then Exit Function

'Open forms module
'DoCmd.OpenModule "Form_" & sFrmName
Application.VBE.ActiveVBProject.VBComponents("Form_" & sFrmName).CodeModule.CodePane.Show

Upvotes: 2

Related Questions