Solved Open Form and Apply Filter to Subform (1 Viewer)

MattBaldry

Self Taught, Learn from the Forums
Local time
Today, 14:04
Joined
Feb 5, 2019
Messages
293
Hi all,

I have been looking and trying and cannot find the right syntax to open a form and apply a filter to the subform.

Main form is frmProductionManagement, subform is sfrmProductionManagement is in Continuous Form view.

If I set the filter in the subform in design mode to [Outstanding] > 0, it works. The issue I have is I want to open it in 2 ways from my ribbon, one with [Outstanding] > 0 and the other with [Outstanding] = 0

Code:
DoCmd.OpenForm "frmProductionManagement",acNormal, , [Forms]![frmProductionManagement]![sfrmProductionManagement]![Outstanding] > 0

This is the error I get, I just cannot get my head around where I have gone wrong.

1713364844811.png


Do I need to open the form and then apply filter as a separate step onto the subform?

Hopefully someone can slap my brain and point out the basic mistake I have made.

~Matt
 

theDBguy

I’m here to help
Staff member
Local time
Today, 06:04
Joined
Oct 29, 2018
Messages
21,480
You might try using the OpenArgs argument and the Open event of the main form to filter the subform.
 

MattBaldry

Self Taught, Learn from the Forums
Local time
Today, 14:04
Joined
Feb 5, 2019
Messages
293
You might try using the OpenArgs argument and the Open event of the main form to filter the subform.
I actually just solved this myself thanks to an old post from IslaDogs. I used the below.

Code:
DoCmd.OpenForm "frmProductionManagement"
    [Forms]![frmProductionManagement]![sfrmProductionManagement].Form.Filter = "[Outstanding] > 0"
    [Forms]![frmProductionManagement]![sfrmProductionManagement].Form.FilterOn = True

I shall mark as solved :)

~Matt
 

theDBguy

I’m here to help
Staff member
Local time
Today, 06:04
Joined
Oct 29, 2018
Messages
21,480
I actually just solved this myself thanks to an old post from IslaDogs. I used the below.

Code:
DoCmd.OpenForm "frmProductionManagement"
    [Forms]![frmProductionManagement]![sfrmProductionManagement].Form.Filter = "[Outstanding] > 0"
    [Forms]![frmProductionManagement]![sfrmProductionManagement].Form.FilterOn = True

I shall mark as solved :)

~Matt
Good work!
 

Users who are viewing this thread

Top Bottom