以编程方式设置文本框值但返回运行时错误438

时间:2013-12-13 00:13:45

标签: vba ms-access

我正在尝试根据我在组合框中选择的值和另一个文本框中的预先存在的值来设置文本框的值。两个控件都在表单中的连续子表单中。当我在组合框中选择一个值时,我得到以下结果:

Run-time error '438':

Object doesn't support this property or method

我的代码如下所示:

Private Sub Combo1_Dirty(Cancel As Integer)

    Dim con As ADODB.Connection

     Set con = Application.CurrentProject.Connection

    Dim rs As ADODB.Recordset

    Set rs = New ADODB.Recordset

    ssql = "(SELECT TABLE1.DESCRIPTION As d1 " & _
"FROM TABLE1 " & _
"INNER JOIN TABLE2 ON " & _
"(TABLE1.CATEGORY = TABLE2.CATEGORY) " & _
"AND (TABLE1.LEVEL = TABLE2.LEVEL) " & _
"WHERE " & _
"(((TABLE1.LEVEL)= " & [Forms]![MainForm].[Subform].[Combo1] & ") " & _
"AND ((TABLE2.CATEGORY)= '" & [Forms]![MainForm].[Subform].[CATEGORY] & "'));)"

    rs.Open ssql, con

    Do Until rs.EOF = True

       [Forms]![MainForm].[Subform].TextBox1.SetFocus

       [Forms]![MainForm].[Subform].TextBox1.Text = rs.Fields!d1

       rs.MoveNext

    Loop

End Sub

我在线搜索了很多,并且无法弄清楚我做错了什么。任何帮助是极大的赞赏。谢谢!

1 个答案:

答案 0 :(得分:0)

尝试改为[Forms]![MainForm]。[Subform] .Form.TextBox1

[Subform]是指Mainform上的对象。您需要使用Form对其进行限定以引用其中的对象。