Help!

S

SF

I have an unbound form with a combobox that list Year (e.g 1,2,3,4,5,6). On
the unbound form I have a subform to display data for each year that select
in the combobox (e.g. the subform would list projects in year 1 if the
combobox selet 1 and so one). Now come the difficult part. I want to display
the entire records for multiple years when the form is first open. I cannot
find a way to do that since the record in the sub form is totally depend on
the list that select.

Could somebody have another way of thinking?

SF
 
D

Dirk Goldgar

SF said:
I have an unbound form with a combobox that list Year (e.g
1,2,3,4,5,6). On the unbound form I have a subform to display data
for each year that select in the combobox (e.g. the subform would
list projects in year 1 if the combobox selet 1 and so one). Now come
the difficult part. I want to display the entire records for multiple
years when the form is first open. I cannot find a way to do that
since the record in the sub form is totally depend on the list that
select.

Could somebody have another way of thinking?

You delete the Link Master/Child Fields of the subform control so that
it is no longer linked directly to the main form. Then you could use
the AfterUpdate event of the combo box to change the RecordSource of the
subform to return just the records for the selected year. Something
like this:

'----- start of example code -----
Private Sub cboYear_AfterUpdate()

Dim strSQL As String

strSQL = "SELECT * FROM Projects"

If Not IsNull(Me!cboYear) Then
strSQL = strSQL & " WHERE ProjYear = " & Me!cboYear
End If

Me!sfProjects.Form.RecordSource = strSQL

End Sub
'----- end of example code -----
 
Top