我可以使用变量作为Microsoft Access VBA中控件的名称吗 [英] Can I use a variable as the name of a control in Microsoft Access VBA

查看:384
本文介绍了我可以使用变量作为Microsoft Access VBA中控件的名称吗的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Microsoft Access弹出表单,用于查找地址.一旦用户找到了邮政编码,则将地址放入启动它的表单上的各个文本框中.问题在于,该弹出表单是从整个数据库的各种表单启动的,因此将其放入结果的文本框位于不同的位置.

I have a Microsoft Access Popup Form which I use to lookup addresses. Once the user has found the postcode, the address is then put into various text boxes on the form it was launched from. The problem is, this popup form is launched from various forms throughout the database and so the text boxes it puts the result into are in different locations.

我尝试通过以下方式解决此问题.我有一个总在打开的总机,所以我在那上面有一个隐藏的文本框,我以编程方式放置了要从中启动弹出表单的表单的名称.然后,我声明一个字符串变量,将其设置为该隐藏文本框的当前值,如下所示:

I tried to work around this in the following way. I have a switchboard which is open at all times so I have a hidden Textbox on there which I programmatically put the name of the form I am launching the popup form from. I then declare a string variable which is set to the current value of this hidden textbox like so:

Dim currentForm As String
currentForm = [Forms]![foo]![bar]

然后我尝试将我的地址详细信息放入相关的文本框中,如下所示:

I then tried to put my address details into the relevant textboxes like so:

Forms!currentForm![txtCurrentAdd1] = rst![Line1]

但是这不能按计划进行,我在做什么错了?

However this isn't working as planned, what am I doing wrong?

谢谢

推荐答案

任一:

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]

Dim currentForm As Form
Set currentForm = Forms![foobar]

currentForm![txtCurrentAdd1] = rst![Line1]

您可能想阅读bang vs dot.

You might like to read up on bang vs dot.

请介意,整个过程看起来就像您在上游游泳.

Mind you, the whole thing looks a little like you are swimming upstream.

这篇关于我可以使用变量作为Microsoft Access VBA中控件的名称吗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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