通过模块[VBA]获取表单字段值 [英] Get form field value via module [VBA]

查看:72
本文介绍了通过模块[VBA]获取表单字段值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用VBA构建的程序,可以访问. 我有一个带有chDate字段的表单,我需要在名为Global(不是类模块)的模块文件中获取该字段的值.

I have a program built with VBA, in access. I have a form with the field chDate and I need to get the value of the field in a module file named Global (not class module).

我试图访问它,但是我认为我得到了空值,字符串.没有错误. 我不是VBA的专家,它对我来说是新的(我对VBS有经验).

I tried to access it but I think I get empty value, string. not error. I'm no expert with VBA, its new to me (I have experience with VBS).

有人可以帮助我,告诉我如何通过模块文件访问表单字段的值吗?

Can someone please help me and tell me how can I access the value of a form field via module file?

谢谢!

推荐答案

如果您可以提供一些示例代码,则可能有助于我们为您提供解决方案.

If you can provide some sample code, it might help us in trying to get you a solution.

这可能会起作用:

Dim一个对象作为表单的实例,并将该实例设置为新实例.这两行可以做到这一点(假设表单称为frmForm)

Dim an object as an instance of your form, and set the instance to a new instance. These two lines will do that (assuming the form is called frmForm)

Dim theForm as frmForm
Set theForm = new frmForm

然后显示该表格:

theForm.show

表单将成为焦点,因此您可以填充字段.届时,一旦隐藏表单,您的代码就应该能够像这样拉出该字段:

The form will get the focus, so you can populate the fields. At that point, once the form is hidden, your code should be able to pull the field as such:

var1 = theForm.txtFormField.Text

但是,如果您在代码中卸载该表单,则与该表单直接相关的所有变量都将丢失.在这种情况下,您可能需要遵循Oneide的示例,并将一个全局变量设置为form字段的值.您可以在表单的事件处理程序之一中执行此操作.

However, if you unload the form in code, all variables directly tied to the form will be lost. In that case, you might want to follow Oneide's example, and set a global variable to the value of the form field. You can do this in one of the form's event handlers.

这篇关于通过模块[VBA]获取表单字段值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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