germantom
germantom

Reputation: 415

Filtering MS Access subform with vba

I have a quick question. I've developed a booking system that has a sub form containing all the rooms booked on the date displayed (in main form). I've added a combo box to allow users to filter the rooms to only see the ones they select from combo box (re-query the sub-form and then filter).

This works fine apart from the fact my code would sometimes loop through the filtering sub for no apparent reason after reaching the end of the sub?. It displays everything correctly, so this I'm not bothered about (unless it's connected to the real problem).

The real problem I'm having however is when I choose a room that has no bookings for the date displayed. The filter works fine (empty display), but when I then try to choose another room from the combo box the re-query function behind the after update of the combo box does not work!

Has anyone else experienced this before?

The workflow:

Combo box triggers 'after update' event. This re-queries the sub-form, where behind the 'on current' event the filtering of the sub-form happens.

When sub-form is empty I'm unable to perform any further sub-form re-queries.

Upvotes: 0

Views: 1423

Answers (1)

Mike
Mike

Reputation: 144

I do something similar and had a hard time with this but was able to fix it with the following code in my combo_box_afterupdate event.

Dim rs As Object
Me.Form.Filter = ""
Me.Form.Refresh
Set rs = Me.Recordset.Clone
rs.FindFirst "[ValueToFind] = '" & Me![MyComboBoxValue] & "'"
If Not rs.EOF Then Me.Bookmark = rs.Bookmark

Also be sure to link parent and child as last person mentioned.

Upvotes: 1

Related Questions