I am using Access 2007 and have created a split form.
Using the wizard I then added a combo box for the user to select records based on a field called Formatted Cost Code. The wizard left a macro in the After Update property of the control for the combo box. I converted this to VBA using the Access 'conversion wizard', resulting in the following code,
Private Sub cmbBxFormattedCostCode_AfterUpdate()
On Error GoTo Combo39_AfterUpdate_Err
DoCmd.SearchForRecord , "", acFirst, "[RecordID] = " & Str(Nz(Screen.ActiveControl, 0))
Combo39_AfterUpdate_Exit:
Exit Sub
Combo39_AfterUpdate_Err:
MsgBox Error$
Resume Combo39_AfterUpdate_Exit
End Sub
But I want the user to be able to filter out all records that don't match the "cost code" selection. So I searched 'Net and found a posting called "Filtering split form records from combo box", and found a response by Bob Larson on 10/02/2009. He suggested the following code be inserted into the After Update property of the control for the combo box,
Me.Filter = "[Formatted Cost Code]='" & [cmbBxFormattedCostCode] & "'"
Me.FilterOn = True
I have inserted this code but I am not getting the desired effect. When I make a selection using the combo box I see the records I want in the datasheet view but I also see all other records.
What am I doing wrong?
Using the wizard I then added a combo box for the user to select records based on a field called Formatted Cost Code. The wizard left a macro in the After Update property of the control for the combo box. I converted this to VBA using the Access 'conversion wizard', resulting in the following code,
Private Sub cmbBxFormattedCostCode_AfterUpdate()
On Error GoTo Combo39_AfterUpdate_Err
DoCmd.SearchForRecord , "", acFirst, "[RecordID] = " & Str(Nz(Screen.ActiveControl, 0))
Combo39_AfterUpdate_Exit:
Exit Sub
Combo39_AfterUpdate_Err:
MsgBox Error$
Resume Combo39_AfterUpdate_Exit
End Sub
But I want the user to be able to filter out all records that don't match the "cost code" selection. So I searched 'Net and found a posting called "Filtering split form records from combo box", and found a response by Bob Larson on 10/02/2009. He suggested the following code be inserted into the After Update property of the control for the combo box,
Me.Filter = "[Formatted Cost Code]='" & [cmbBxFormattedCostCode] & "'"
Me.FilterOn = True
I have inserted this code but I am not getting the desired effect. When I make a selection using the combo box I see the records I want in the datasheet view but I also see all other records.
What am I doing wrong?