我有一个Microsoft Access弹出窗体,我用它来查找地址.一旦用户找到了邮政编码,地址就会被放入启动表格的各种文本框中.问题是,这个弹出窗体是从整个数据库中的各种形式启动的,因此它将结果放入的文本框位于不同的位置.
我尝试以下列方式解决这个问题.我有一个总是打开的交换机,所以我有一个隐藏的文本框,我以编程方式将我正在启动弹出窗体的表单的名称.然后我声明一个字符串变量,它被设置为这个隐藏文本框的当前值,如下所示:
Dim currentForm As String
currentForm = [Forms]![foo]![bar]
Run Code Online (Sandbox Code Playgroud)
然后我尝试将我的地址详细信息放入相关的文本框中,如下所示:
Forms!currentForm![txtCurrentAdd1] = rst![Line1]
Run Code Online (Sandbox Code Playgroud)
然而,这不按计划工作,我做错了什么?
谢谢
或者:
Dim currentForm As String
''Not sure where the two parts are coming from
''but you cannot have them like that
currentForm = "foobar"
Forms(currentForm).[txtCurrentAdd1] = rst![Line1]
Run Code Online (Sandbox Code Playgroud)
要么
Dim currentForm As Form
Set currentForm = Forms![foobar]
currentForm![txtCurrentAdd1] = rst![Line1]
Run Code Online (Sandbox Code Playgroud)
你可能想读一下bang vs dot.
请注意,整个事情看起来有点像你在上游游泳.
您可以访问其他表单上的控件,如下所示:
Dim FormName As String
Dim ControlName As String
FormName = "YourForm"
ControlName = "YourTextbox"
Forms(FormName).Controls(ControlName) = "New Value"
Run Code Online (Sandbox Code Playgroud)