How to disable a Form Filter when opening the form

PNGBill

Win10 Office Pro 2016
Local time
Tomorrow, 03:07
Joined
Jul 15, 2008
Messages
2,271
I have a continuous form that works fine and shows all the records it should but I would also like to have this form open when a command button is clicked on a Record so when it opens, only that record will show.
normally this is straight forward how ever when the form opens all records are displayed (300 odd) rather then the one record the Link Criteria should show.

I suspect this code is the issue which is the Form On Load Event.

Is it possible to ignore this code when the form is opened by the command button mentioned above?:confused:

Code:
Private Sub Form_Load()
    
    Me.Filter = "LoanCurrentBalance>0"
    Me.FilterOn = True
    
    Me.OrderBy = "EDName, FullName, LoanID"
    Me.OrderByOn = True

End Sub
 
You could have a Public boolean flag on the form that you set when clicking the button and in the load event of the opening form you check that flag and if it is true you bypass your filter code and if false you use it.
 
Thanks Bob,
By Public Boolean Flag do you mean any control on the on click form.
I could add an unbound text box control, make it invisible and have the word "OverdueLetterNo: typed in the control.
When the command button is clicked, the text is changed to "OverdueLetterYes"

And in the opening Form I use an if then statement to check the other forms text box controls value.

As this form will still be open, the control should be able to be read.

Am I on the right track ??
 
I wouldn't use a text box. But in a Standard Module just put

Code:
Public blnNoRun As Boolean

Then in the click event of the button before your open form code you just use:
Code:
blnNoRun = True

And then in your other code you use:
Code:
Private Sub Form_Load()
 
[COLOR=red][B]If Not blnNoRun Then[/B][/COLOR]
 
    Me.Filter = "LoanCurrentBalance>0"
    Me.FilterOn = True
 
    Me.OrderBy = "EDName, FullName, LoanID"
    Me.OrderByOn = True
End If
 
' resets it
[B][COLOR=red]blnNoRun = False[/COLOR][/B]
 
End Sub
 
You're excused Bob :p lol. Sometimes I forget it exists especially when I'm not trying to pass arguments between objects.
 
Meanwhile I have used the control method and found why it is not good to use.

The form opens fine but of course when we open the form in normal use, the On Click form isn't open so the code crashes:eek:

Your Idea Bob will mean the public binNoRun is always available to compare.

I have done some OpenArgs recently and will check this out.

Thanks Bob and vbaInet:)
 
Your Idea Bob will mean the public binNoRun is always available to compare.
Yeah, and that is not a bad thing. That's why we reset it at the end of the code.
I have done some OpenArgs recently and will check this out.
Should work fine with OpenArgs.
 
Problem Solved with OpenArgs
Code on Form to open
Code:
Private Sub Form_Load()
    
    If Not IsNull(Me.OpenArgs) Then
        Me.Filter = Me.OpenArgs
        Me.FilterOn = True
    Else
        Me.Filter = "LoanCurrentBalance>0"
        Me.FilterOn = True
        Me.OrderBy = "EDName, FullName, LoanID"
        Me.OrderByOn = True
    End If

End Sub

and code on Form where click was done
Code:
Private Sub CmdFrmOverdueLetterMainForm_Click()
On Error GoTo Err_CmdFrmOverdueLetterMainForm_Click

    Dim stDocName As String
    Dim stLinkCriteria As String
    
    Me.Parent!OverdueLetterFlag.Caption = "OverdueLetterYes"

    stDocName = "FrmOverdueLetterMainSubForm"
   
    DoCmd.OpenForm stDocName, , , , , , "[LoanID]=" & Me![LDPK]

Exit_CmdFrmOverdueLetterMainForm_Click:
    Exit Sub

Err_CmdFrmOverdueLetterMainForm_Click:
    MsgBox Err.Description
    Resume Exit_CmdFrmOverdueLetterMainForm_Click
    
End Sub

Thanks again
 

Users who are viewing this thread

Back
Top Bottom