C
Christopher Hickman via AccessMonster.com
I have a form for entering monthly cost data for a bunch of equipment. The
table has an EquipID, a year, and 12 more columns for the months in the
year. The form is meant to display all the equipment in the database,
filtered by a given year and month. The way I do this is I have two combo
boxes, one for month, and one for year. The Month_Combo has a value list
row source listing the months, and the Year_Combo just pulls the years
available in the table (SELECT DISTINCT Year FROM CostData.
Both combo boxes have code on their AfterUpdate event that simply calls the
AfterUpdate code for the form:
Private Sub Form_AfterUpdate()
If Not IsNull(Year_Combo) Then
'This sets the filter to only show me the selected year
Me.Filter = "[Year] = " & Year_Combo
Me.FilterOn = True
End If
If Not IsNull(Month_Combo) Then
'This sets the control source for the Cost text field
'so that it matches the selection from the month combo
'box (The column names match the entries in the Month_Combo)
Me.Cost.ControlSource = Month_Combo
End If
End Sub
This functions as I want, making the cost fields in the form display the
data from the appropriate column for the appropriate year. The problem is
that whenever this code is executed, Month_Combo goes blank. Year_Combo
goes blank if Month_Combo changes, too.
I've tried adding Me.Month_Combo.Requery to try to make it refresh, but
that didn't work. If I comment out the setting of the ControlSource, it
fixes the display problem (but of course my functionality is then gone).
This is driving me batty.
Does anyone have any idea how to make my combo boxes display their
selections?
Thanks,
Christopher
table has an EquipID, a year, and 12 more columns for the months in the
year. The form is meant to display all the equipment in the database,
filtered by a given year and month. The way I do this is I have two combo
boxes, one for month, and one for year. The Month_Combo has a value list
row source listing the months, and the Year_Combo just pulls the years
available in the table (SELECT DISTINCT Year FROM CostData.
Both combo boxes have code on their AfterUpdate event that simply calls the
AfterUpdate code for the form:
Private Sub Form_AfterUpdate()
If Not IsNull(Year_Combo) Then
'This sets the filter to only show me the selected year
Me.Filter = "[Year] = " & Year_Combo
Me.FilterOn = True
End If
If Not IsNull(Month_Combo) Then
'This sets the control source for the Cost text field
'so that it matches the selection from the month combo
'box (The column names match the entries in the Month_Combo)
Me.Cost.ControlSource = Month_Combo
End If
End Sub
This functions as I want, making the cost fields in the form display the
data from the appropriate column for the appropriate year. The problem is
that whenever this code is executed, Month_Combo goes blank. Year_Combo
goes blank if Month_Combo changes, too.
I've tried adding Me.Month_Combo.Requery to try to make it refresh, but
that didn't work. If I comment out the setting of the ControlSource, it
fixes the display problem (but of course my functionality is then gone).
This is driving me batty.
Does anyone have any idea how to make my combo boxes display their
selections?
Thanks,
Christopher