如何Debug Access 中的VBA

本文探讨了在VBA编辑器中使用F5运行子程序或用户窗体及F8逐步执行时遇到的问题。解释了当子程序含有参数时F5将显示宏列表而非直接执行的原因,并提供了在立即窗口中调用带有参数的函数的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

When I click the "Run Sub/UserForm (F5)" command in the VBA editor I
get a macro list. The code doesn't execute. The "Step Into (F8)"
command doesnt work either. What am I doing wrong?

>On Mar 30, 10:36 am, Matthias Klaey <m...@hotmail.com> wrote:
>> "nuages" <nua...@apex.net.au> wrote:
>> >When I click the "Run Sub/UserForm (F5)" command in the VBA editor I
>> >get a macro list. The code doesn't execute. The "Step Into (F8)"
>> >command doesnt work either. What am I doing wrong?
>>
>> You can only run code directly with F5 if the sub/function does not
>> have any arguments. If the cursor is positioned in a Sub/Function that
>> has arguments, or if the cursor is in the empty space between two
>> procedures, then the macro list pops up. This is the Access standard.
>>
>> If you want to run a Sub/Function that has arguments, you must do so
>> in the immediate window (Ctrl+G):
>>
>> Public MyFunc(intX As Integer) As Integer
>> MyFunc = 2 * intX
>> End Function
>>
>> ? MyFunc(3)
>>
>> 6
>>
>> HTH
>> Matthias Kläy
>> --www.kcc.ch
>
>Thanks very much for quick reply. I now am more aware on how F5, F8
>works. As it happens the the following procedure doesn't have
>arguments and it works properly. But when I try and run it in the
>Editor I still get a Macro list. Any ideas?
>
>Option Compare Database
>Option Explicit
>
>Public Function faq_Open_Correct_Startup_Form()
>'The purpose of this function procedure is to run the
>'following sub procedure at startup.
>sub_Open_Correct_Startup_Form
>End Function

Sorry .. I forgot to mention that F5 only works in standard modules,
not in Form or Report or Class modules. You will have to call these
procedures from the immediate window too, e.g.

Call Forms("MyForm").faq_Open_Correct_Startup_Form

Greetings,
Matthias Kläy
--
www.kcc.ch
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值