subform issue

  • Thread starter Thread starter John
  • Start date Start date
J

John

Greetings. I have a mainform (FormA) and on it there is a
combo box (ComboA) and a tab control (TabA). On the tab
control is subform (SubformA) that I would like to specify
the record source to. I am attempting to do this in the
AfterUpdate event of the combobox. But I am not getting
it to work.
Anyone with any suggestions as to what I am doing wrong?
Thanks to anyone who responds.
*** John
 
If you are trying to get the subform to show the records that match the
combo in the main form, you could just enter the name of the combo in the
subform control's LinkMasterFields property, and the name of the matching
subform field in LinkChildFields.

You should also be able to take the approach you suggested, and use the
AfterUpdate event of the combo to assign a SQL string to the RecordSource of
the form in the subform control:

Private Sub MyCombo_AfterUpdate()
Dim strSQL As String
If Not IsNull(Me.MyCombo) Then
strSQL = "SELECT * FROM [MySubformTable] WHERE [MyForeignKey] = " &
Me.MyCombo & ";"
Me.[NameOfYourSubformControlHere].Form.RecordSource = strSQL
End If
End Sub

If the combo's bound column is a Text type field, you need extra quotes:
strSQL = "SELECT * FROM [MySubformTable] WHERE [MyForeignKey] = """ &
Me.MyCombo & """;"

You may find Access automatically decides to assign values the
LinkMasterFields/LinkChildFields when you do this, and so you have to clear
those properties before any records show up.
 
John said:
Greetings. I have a mainform (FormA) and on it there is a
combo box (ComboA) and a tab control (TabA). On the tab
control is subform (SubformA) that I would like to specify
the record source to. I am attempting to do this in the
AfterUpdate event of the combobox. But I am not getting
it to work.
Anyone with any suggestions as to what I am doing wrong?


It's very difficult to say what you're dong wrong when you
never said what you're doing ;-\

Ican tell you that the tab control has nothing to do with
the issue, i.e. you can do the same thing you should do
whitout a tab control.

To set a subform's record source, use this kind of syntax:

Me.subformCONTROLname.Form.RecordSource = strSQL
 
Back
Top