Forum Discussion
OpenArgs, Filter
- Dec 31, 2021
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 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
- Tony2021Dec 31, 2021Steel Contributor
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- Dec 31, 2021
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- Tony2021Dec 31, 2021Steel Contributorthat 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!