Originally Posted by
Lou_Reed
<snip>.... But what if it is not an embedded macro. There is o button with its properties easily available. What do you do then?
Any help appreciated Thanks in advance.
In VBA code, you can execute a (standard) macro using the command
Code:
DoCmd.RunMacro ("FormHeading")
Once you convert the macro to VBA code, you just call the sub.
So here is one example:
You convert the "FormHeading" macro to VBA. The VBA looks like
Code:
Option Compare Database
Option Explicit
'------------------------------------------------------------
' FormHeading
'
'------------------------------------------------------------
Function FormHeading()
On Error GoTo FormHeading_Err
With CodeContextObject
TempVars.Add "Heading", DLookup("[Heading]", "tblDatabaseConfig", "[ID] = 1")
DoCmd.SetProperty "lblHeading", acPropertyCaption, TempVars("Heading") + " - " + .Caption
TempVars.Remove "Heading"
End With
FormHeading_Exit:
Exit Function
FormHeading_Err:
MsgBox Error$
Resume FormHeading_Exit
End Function
Now, I would fix the conversion; I would change the code to
Code:
Option Compare Database
Option Explicit
'------------------------------------------------------------
' FormHeading
'------------------------------------------------------------
Function FormHeading()
On Error GoTo FormHeading_Err
Forms!DivisionDashboard.lblHeading.Caption = DLookup("[Heading]", "tblDatabaseConfig", "[ID] = 1")
FormHeading_Exit:
Exit Function
FormHeading_Err:
MsgBox Err.Number & " - " & Err.Description
End Function
In the code for the "DivisionDashboard" form, there is a "Form_Open" procedure. The procedure is
Code:
Private Sub Form_Open(Cancel As Integer)
DoCmd.RunMacro ("FormHeading")
Switchboard.Requery
Update_Actions
End Sub
Since this code is calling a macro, you must edit the code to execute the VBA.
It would look like:
Code:
Private Sub Form_Open(Cancel As Integer)
' DoCmd.RunMacro ("FormHeading")
Call FormHeading
Switchboard.Requery
Update_Actions
End Sub
Everyplace in the code, comment out the "DoCmd.RunMacro" command and add the "Call FormHeading" line.
I would also add a new Module named "ConvertedMacros" and move all of the converted macros VBA code to the new module, then delete all of the modules that have the name "Converted Macro- xxxxxxxxxxx".... except the module "Converted Macro- AutoExec". I would delete that one totally.
(the module and code, not the macro)