View Full Version : Solved: Open Form Code With VBA ... Possible?
DarkSprout
01-11-2008, 03:53 AM
Is it possible to to open the code for a specific form With VBA?
i.e. DoCmd.ViewCode acForm, "frm_FormName"
ps. I know the above code doesn't exist in Access, but does in word.
=DarkSprout=
just an example to see how it works
Sub GetFormVBACode()
Dim mdl As Module
DoCmd.OpenForm ("FormName")
Set mdl = Forms!FormName.Module
MsgBox mdl.Lines(1, 10)
DoCmd.Close acForm, "FormName"
End Sub
Insert your form name instead of FormName.
Form must be opened inorder to read its code
Carl A
01-11-2008, 06:59 AM
You can use OpenModule of the DoCmd. The Form has to be open for this to work.
DoCmd.OpenModule "Form_Form1", "Your Procedure Here"
DarkSprout
01-11-2008, 07:07 AM
I love the Code, Thanks..
I Modded It Slightly, So That You Can View Any Form Code
Sub GetFormVBACode(FormName As String)
Dim mdl As Module
DoCmd.OpenForm (FormName)
Set mdl = Forms(FormName).Module
MsgBox mdl.Lines(1, 10)
DoCmd.Close acForm, (FormName)
Set mdl = Nothing
End Sub
But, I Want To View The CodeWindow for the Quoted Form Its-self... Can This Be Done?
don't know if what you need. it's just an example on Carl idea...it needs improvement
Public Sub FormVBACode(FormName As String)
On Error Resume Next
DoCmd.Close acModule, "Form_" & FormName
DoCmd.Close acForm, (FormName)
On Error GoTo 0
VBE.MainWindow.WindowState = 1
DoCmd.OpenForm (FormName)
DoCmd.OpenModule "Form_" & FormName, "MyProc"
DoCmd.Close acForm, (FormName)
VBE.MainWindow.WindowState = 2
End Sub
You have to point a procedure (in the code called MyProc).
DarkSprout
01-11-2008, 09:50 AM
Thanks one And All, Job Done
I created a AutoKeys Macro
^+{INS} with a RunCode to call the Function: ViewCode()
FormVBACode then Does all the work
Public Function ViewCode()
'// Call for User to enter Admin Password Here
If AdminPassword = True Then
Call FormVBACode(Screen.ActiveForm.Name)
End If
End Function
Public Sub FormVBACode(FormName As String)
DoCmd.OpenModule "Form_" & FormName
VBE.MainWindow.WindowState = vbext_ws_Maximize
End Sub
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.