Ms access M7S访问:评估包含变量的字符串?

Ms access M7S访问:评估包含变量的字符串?,ms-access,vba,Ms Access,Vba,我正在尝试修改数据表标题上的标签。以下命令生成所需的结果: Forms!mainform![mySubform].Form.Controls("Label47").Properties("Caption") = "Test47" 我的最终目标是使用变量修改循环中的一组标签标题。在以下方面没有成功: dim intLabel as integer dim strLabel as string intLabel = 47 'the first Label "Label47" do while

我正在尝试修改数据表标题上的标签。以下命令生成所需的结果:

Forms!mainform![mySubform].Form.Controls("Label47").Properties("Caption") = "Test47"
我的最终目标是使用变量修改循环中的一组标签标题。在以下方面没有成功:

dim intLabel as integer
dim strLabel as string

intLabel = 47  'the first Label "Label47"

do while intLabel < 99
    strLabel = "Forms!mainform![mySubform].Form.Controls('Label" & intLabel & "').Properties('Caption') = 'Test" & intLabel & "'"
    Eval (strLabel)
    intLabel - intLabel + 1
Loop

完成这项任务有什么建议吗?

我会忘记使用Eval的尝试,直接赋值:

dim intLabel as Long
dim strLabel as String

intLabel = 47  'the first Label "Label47"

Do While intLabel < 99
    Forms!mainform![mySubform].Form.Controls("Label" & intLabel).Properties("Caption") = "Test" & intLabel
    intLabel - intLabel + 1
Loop

为什么要改为单引号而不是双引号?要匹配原始行,您需要使用strLabel=Forms!主窗体![mySubform].Form.ControlsLabel&intLabel.propertiesscaption=Test&intlabelum,如果不将替换为“”,则无法构造有效的字符串值。我在这里遗漏了什么吗?对不起-让我重写一下-我忘了你在字符串strLabel=Forms中创建了一个字符串!主窗体![mySubform].Form.ControlsLabel&intLabel&.propertiesscaption=Test&intLabel&好的,我明白了!:Eval strLabel行显示:2770作为OLE对象引用的对象不是OLE对象。结果字符串的格式与预期的一致——与上面的测试字符串相匹配。我不习惯访问的Eval命令,所以我不能对它的局限性发表评论。Excel版本只允许您评估Excel本身可以访问的内容,即您不能引用作为用户表单或代码模块一部分的对象等。Excel版本不允许您执行分配,只允许评估内容。因此,Access的版本可能也受到类似的约束。YowE3K,这会产生所需的结果。有趣的谢谢