I struggle with VB and have not yet figured out how to place a VB command in a macro unless it is already on the list of "Actions" that are on the list. Any further advice?
Adding code is similar to adding a macro to a form. If you go to a button, field, label or the form itself and property Event you will see 3 dots just to the right of where you enter macro name and that drop down arrow.
If you click on the 3 dots and there is a macro already there then you will see the macro open in Design view. So go to something like a field/textbox where you don't have a macro and to its Event property. Pick the Event and click the 3 dots and a box will open and one of the options is Code Builder. Click Code Builder and a screen will open that shows something like
Private Sub Label291_Click()
End Sub
The code goes in between. In this case it would attach to Label291 and is for OnClick.
You can't run code like above from a macro because such code is part of the form. To run code from a macro the code must be in a module and then the function name (not module name) is done from the macro with RunCode action and FunctionName()
A Module is similar to a Macro except it has code instead of macro actions. As you know if you make a macro to open a form then you can use that macro all over the data base. Code that is in a module is the same.
The code you place in this example
Private Sub Label291_Click()
End Sub
is part of the form. If you exported the form then the code would come with the form.
If someone posts an answer that looks similar to this
Public Function
Full of code
End Function
that goes in a module, not to an event on a form. Public means...to use wherever, just like a macro.
The major difference between code and macro is code allows much more to be done. Macros are a little like a motor mechanic whose work is limited by the parts which are available. Code would be like a motor mechanic who can actually make parts that are not available over the counter.