Forum Discussion

Tony2021's avatar
Tony2021
Steel Contributor
Dec 31, 2021

OpenArgs, Filter

Hello Experts,

 

I have a form that has On Load that opens if Nz OpenArgs.  The form's data tab shows its filtered to [LetterOfCreditID] = xx (whatever record the [LetterOfCreditID] was filtered to)

It works fine.  Below is what the form's filter shows in design: 

 

I also have a button on the form that overides the filter shown above and filters based on "[COID]=" (this is a macro and essentially overides the OpenArgs and shows all records based on COID:

 

The form's filter appears to have not changed and still says [LetterofCreditID] = 21 (but it is filtering to the "[COID]=" & [COID and so I guess the form's filter doesnt update yet and that is ok)

 

What I want to do is revert back to what the form's filter says in the first pic above [LetterOfCreditID] = 21 but how can I do this?  I want to essentially override the "[COID]=" filter I put on the form with the macro and use the value in the form's filter, which still shows [LetterOfCreditID] = 21 (I dont want to hard code to "21"...its only an example in this case and will change based on how the form was initially filtered with OpenArgs.)

 

Let me know if it is not clear.  

Grateful for the assistance. 

 

  • Hi,

     

    I did a quick test with that setting and it works here, i.e. the ApplyFilter macro filter gets replaced by the new filter. Maybe in your case there's sth else involved. What happens when you try it? Nothing at all?

     

    Personally I would not mix VBA mit a macro but do all filtering by code with

    Me.Filter = ...

     

    Maybe this also enables you to set back the filter as described, by just calling OnLoad again. No Requery/Refresh etc. is necessary when I do this here. I just have to change the Filter property.

     

    Servus
    Karl
    ************
    Access News
    Access DevCon

  • Hi,

     

    The order of what you want to accomplish is not very clear to me. You want to filter for the OpenArgs first, then with the ApplyFilter macro and as a third step back to the OpenArgs filter? Or differently?

    With which code OnLoad do you set the filter based on the OpenArgs?

    In which event do you call the macro?

    Where and when do you want to "reactivate" the first filter? With a button in the form?

    The right method depends on such details of your current implementation and on your concrete requirements.

     

    Servus
    Karl
    ************
    Access News
    Access DevCon

    • Tony2021's avatar
      Tony2021
      Steel Contributor

      Karl_Donaubauer 

      Hi Karl,
      yes the order as you mention above is correct.
      1. OpenArgs ([LetterofCreditID])
      2. Filter ([COID]) this is a button on frmLCAmendHistory
      3. How to revert back to filter ([LetterofCreditID]) is the issue.

      Below is the OpenArgs on the form frmLetterOfCredit that opens the form to filter FrmLCAmendHistory:

       

      The form where I use OpenArgs (frmLetterOfCredit):
      Private Sub cmdAmendLC_Click()
      If CurrentProject.AllForms("FrmLCAmendHistory").IsLoaded = False Then
      DoCmd.OpenForm "FrmLCAmendHistory", , , , , , OpenArgs:=Me.txtLCID & ";" & Me.txtProjIDfk & ";" & Me.Amount & ";" & Me.txtLCNo

      Else
      DoCmd.Close acForm, "FrmLCAmendHistory"
      DoCmd.OpenForm "FrmLCAmendHistory", , , , , , OpenArgs:=Me.txtLCID & ";" & Me.txtProjIDfk & ";" & Me.Amount & ";" & Me.txtLCNo

      End If

       

      On Load of frmLCAmendHistory (initially filters for [LetterOfCreditID]:
      If Nz(Me.OpenArgs, "") <> "" Then
      If Not Me.NewRecord Then
      Me.Filter = "[letterofcreditID] = " & Split(Me.OpenArgs, ";")(0)

      Me.FilterOn = True
      Else
      '/this is a new record
      'MsgBox Split(Me.OpenArgs, ";")(2)

      Me.letterofcreditID = Split(Me.OpenArgs, ";")(0)

      End If
      End If

       

       

      Let me know if still not clear.  Thank you

      • Hi,

         

        It should work to get back the first filtering e.g. with the click on another button, where you simply call the OnLoad procedure again with:

         

        Form_Load

         

        Servus
        Karl
        ************
        Access News
        Access DevCon

         

Share