To paste a macro from Stack Overflow into Access

佐手、 提交于 2019-12-20 07:29:54

问题


My question seems to be very silly, but I haven't found solution myself.

Is there a way to simply paste a macro (example) from Stack Overflow in Access? Or, alternatively, paste it from Access to Stack Overflow?

I know, it is very easy in Word and Excel. But I can't understand how to do it in Access.


回答1:


Basic questions certainly deserve asking, if they're not duplicates.

There are a couple of different cases:

  1. Add VBA on a form event (this case)

    • Open up the form in design view
    • Identify the control you want to add the macro to (the part before the _ is the control name, the part after the _ is the event name, so the KeyDown event on the form control.

    • Identify the event you want to add code to on the event pane

    • Press the builder ... thing
    • Choose Code Builder and press OK.
    • You will see some event code has already been added. Replace that with the copy-pasted code.

  1. Add VBA (function or sub) outside of a form (triggered elsewhere, such as a user-defined function for use in queries)
    • Open up the VBA editor by hitting Alt + F11
    • Choose Insert -> Module in the top bar
    • Paste the code
  2. Paste a normal, non-VBA macro using AXL
    • Create a macro on the create tab on the ribbon
    • Select the body of the macro by clicking the blank space inside it (not the area where you can create new controls)
    • Hit Ctrl + V to paste
  3. Paste an Access data macro using AXL
    • Open the table you want to add the data macro to in design view.
    • In the ribbon, click Create data macros, choose and click the right event. You can identify the event by looking at the event property of the datamacro tag, for example <DataMacro Event="AfterInsert"> = On After Insert
    • Select the body of the macro by clicking the blank space inside it (not the area where you can create new controls)
    • Hit Ctrl + V to paste

Note that questions about non-VBA macros rarely contain the AXL necessary to paste it. Pasting AXL is somewhat contra-intuitive, as you don't paste it in a textbox and the result isn't text.



来源:https://stackoverflow.com/questions/49487403/to-paste-a-macro-from-stack-overflow-into-access

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!