I'm currently using Access 2007 to create a form where a combo box filters an editable subform.
The subform is based on a query which takes a Project_ID and from the combo box and filters the subform table based on that Project_ID number. When in form view I am able to change the combo box and after manually refreshing filter the subform. However the subform does not filter automatically with the combo change.
I can't figure out what is going wrong. I've tried multiple VBA variations but nothing works. I am currently using this VBA script after change to lode the subform.
Private Sub cboProjectSelect_AfterUpdate()
Me!Project_Tracker_Subform.Form.Requery
End Sub
Your current AfterUpdate
code is merely asking the sub form to requery the existing filter criteria, which will result in the same records being displayed.
In your case, you are wanting to update the subform filter criteria to reference the new value selected in your ComboBox. To do so, you would need something like this:
Dim mssql As String
If Len(Me.cboProjectSelect.Value & "") > 0 Then
mssql = "[Project_ID] = " & Me.cboProjectSelect.Value
Me.Project_Tracker_Subform.Form.Filter = mssql
Me.Project_Tracker_Subform.Form.FilterOn = True
End If
This code will only update the subform if a value is chosen in the ComboBox (ie if the user clears the ComboBox value, the If
statement will prevent updating the subform)
Then this code sets your new filter and tells the subform to execute the filter with FilterOn = True
.
In the case where the user does clear the ComboBox, maybe you would want to remove all filtering from the subform. In this case, you could add an Else
clause, such as:
Else
Me.Project_Tracker_Subform.Form.FilterOn = False
End If
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.