将宏从堆栈溢出粘贴到Access中 [英] To paste a macro from Stack Overflow into Access

查看:94
本文介绍了将宏从堆栈溢出粘贴到Access中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题似乎很愚蠢,但我自己还没有找到解决方法.

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

有没有一种方法可以简单地粘贴宏(示例 )中的堆栈溢出?还是将其从Access粘贴到堆栈溢出?

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

我知道,在Word和Excel中这非常容易.但是我不明白如何在Access中做到这一点.

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

推荐答案

基本问题肯定不是重复的,也应该提出来.

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

有两种不同的情况:

  1. 在表单事件上添加VBA(这种情况)

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

  • 在设计视图中打开表单
  • 标识要向其添加宏的控件(_之前的部分是控件名称,_之后的部分是事件名称,因此窗体上的KeyDown事件控制.

  • 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

  1. 在表单之外添加VBA(函数或子函数)(在其他地方触发,例如用于查询的用户定义函数)
    • 通过按 Alt + F11
    • 打开VBA编辑器
    • 在顶部栏中选择插入-> 模块
    • 粘贴代码
  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
  • 在功能区上的创建"选项卡上创建宏
  • 通过单击宏的主体内的空白(而不是可以创建新控件的区域)来选择宏的主体
  • Ctrl + V 进行粘贴
  • 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
  • 在设计视图中打开要向其中添加数据宏的表.
  • 在功能区中,单击"创建数据宏" ,选择并单击正确的事件.您可以通过查看datamacro标签的event属性来识别事件,例如<DataMacro Event="AfterInsert"> =插入后打开
  • 通过单击宏的主体内的空白(而不是可以创建新控件的区域)来选择宏的主体
  • Ctrl + V 进行粘贴
  • 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

请注意,有关非VBA宏的问题很少包含粘贴它所必需的AXL.粘贴AXL有点违反直觉,因为您没有将其粘贴到文本框中并且结果不是文本.

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.

这篇关于将宏从堆栈溢出粘贴到Access中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆