1
votes

I am trying to set the value of a text box based on the value I select in a combo box and a pre-existing value in another text box. Both the controls are in a continuous subform within a form. When I select a value in the combo box, I get the following:

Run-time error '438':

Object doesn't support this property or method

My code looks like this:

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

I've searched quite a bit online, and can't quite figure out what I'm doing wrong. Any help is greatly appreciated. Thanks!

1

1 Answers

0
votes

Try referring instead to [Forms]![MainForm].[Subform].Form.TextBox1

[Subform] refers to the object on Mainform. You need to qualify it with Form to refer to objects within it.