SOLVED

OpenArgs, Filter

Regular Contributor

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: 

Tony2021_0-1640965440859.png

 

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:

Tony2021_1-1640966065526.png

 

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. 

 

6 Replies

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

@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

 

Hi Karl,
Yes, I did try that thinking the same thing but it does not filter back to the initial filter (ie LetterOfCreditID = 21 even though the form says it is filtered to LetterOfCreditID = 21 as shown in the form's data tab filter field (the first pic above).
I added a me.refresh and me.requery thinking its just a refreshing issue but it still doesnt filter back to the intial filter when I first opened the form to OpenArgs (ie LetterOfCreditID = 21).

below is the code I put on the revert back to initial filter (its the same code as the On Load)
Do you have another suggestion?

Private Sub btnRevertFilter_Click()
If Nz(Me.OpenArgs, "") <> "" Then
If Not Me.NewRecord Then 'you need this or else get error if opening form on its own 12/15/21
Me.Filter = "[letterofcreditID] = " & Split(Me.OpenArgs, ";")(0) 

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

End If
End If

Me.Requery


End Sub

best response confirmed by Tony2021 (Regular Contributor)
Solution

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

that was it. It works now. It could have also been the case that I needed to close the form that was opening to the filter and reopen it with the OpenArgs. I am not sure which one it was (getting rid of macro and using only VBA) or closing out the forms and reopening to start "fresh". Anyways, thanks for the help!