如何使用循环在表单上自动填充文本框? [英] How to Autofill Textboxes on a Form using a Loop?

查看:110
本文介绍了如何使用循环在表单上自动填充文本框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我有一个表,其中包含试图在表单上显示的总计列表,我需要从总计表中获取10个总计,并在表单上的10个文本框中显示.

So I have a table that has a list of totals im trying to display on a form, I have 10 totals I need to get from the totals table and display in 10 textboxes on the form.

这10个文本框是"A1, A2, A3...",它使用DLookup查找ID字段号.

The 10 textboxes are "A1, A2, A3..." and its using DLookup to find the ID field number.

Me.TEXTX & X1.Value似乎是语法问题,尽管我不确定如何输入.

It seems like its a syntax issue with Me.TEXTX & X1.Value though I'm not sure how else I can type it.

希望这是有道理的.谢谢!

Hope this makes sense. Thanks!

Private Sub UPDATETOTALS()
    Dim FORMX As String
    FORMX = "GRID"

    Dim TEXTX As String
    TEXTX = "A"

    Dim TABLENAMEx As String, FINDFIELDx As String, GETFIELDx As String
    TABLENAMEx = "GRID_TOTALS"
    FINDFIELDx = "[ID]="
    GETFIELDx = "TODAY"

    Dim X1 As Integer
    For X1 = 1 To 10
        Me.TEXTX & X1.Value = DLookup(GETFIELDx, TABLENAMEx, FINDFIELDx & X1)
    Next X1
End Sub

推荐答案

您不能直接使用串联字符串访问对象引用,因为此类引用不是字符串数据类型.

You cannot access an object reference directly using a concatenated string, as such reference is not of string data type.

相反,您需要通过向该集合的Item方法提供对象名称(作为字符串)来访问相关集合(在本例中为Controls集合)中的对象.

Instead, you will need to access the object from the relevant collection (in this case, the Controls collection), by supplying the name of the object (as a string) to the Item method of that collection.

由于Item方法是集合的默认方法,因此项目名称可以紧随集合之后作为参数.

Since the Item method is the default method for a collection, the item name can immediately follow the collection as an argument.

例如:

For X1 = 1 To 10
    Me.Controls(TEXTX & X1).Value = DLookup(GETFIELDx, TABLENAMEx, FINDFIELDx & X1)
Next X1

这篇关于如何使用循环在表单上自动填充文本框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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