Dec 07 2021 05:19 AM - edited Dec 07 2021 05:21 AM
Hello, I have a form frmLetterOfCredit that the is opened in 1 of 2 ways.
1. From frmProjects .
If from frmProjects I grab the ProjID and filter frmLetterOfCredit On Load
2. I can also open frmLetterOfCredit directly
The issue I am having is if I open the frmLetterOfCredit directly as it seems the filter is still on but I want to turn the filter off if I open frmLetterOfCredit directly (showing all records).
frmLetterOfCredit On Load:
Private Sub Form_Load()
If Len(Me.OpenArgs & "") > 0 Then
Me.Filter = "[ProjIDfk] = " & Split(Me.OpenArgs, ";")(0) 'I use to have >1 field and had a need for "split" but kept as is
Else
Me.Filter = "" 'this doesnt seem to turn the filter off and I want to be triggered if opening frmLetterOfCredit directly and not from frmProjects
End If
frmProjects
Private Sub ProjID_Click()
DoCmd.OpenForm "frmLetterOfCredit", , , , , , OpenArgs:=Me.ProjID
Do you see where I am wrong? My approach might not be correct. Open to other alternatives. FYI: I am not a trained coder.
Dec 07 2021 02:47 PM - edited Dec 07 2021 02:49 PM
SolutionHi,
1. Try to set the form's property FilterOnLoad to False. If that doesn't help, then
2. Instead of Filter="", try this in the OnLoad event of the form:
Me.FilterOn = False
Servus
Karl
*********
Access-Entwickler-Konferenz: https://www.donkarl.com/?AEK
Access DevCon: http://AccessDevCon.com
Access FAQ (de/en): https://www.donkarl.com
Dec 07 2021 06:55 PM - edited Dec 07 2021 07:10 PM
You can also test for Parent property of the form (meaning it is a subform of some Parent form).
Private Sub Form_Load()
Dim varParent As Variant
On Error Resume Next
Set varParent = Me.Parent
If Err Then
Err.Clear
Me.Filter = ""
Me.FilterOn = False
Exit Sub
End If
On Error Goto 0
If Len(Me.OpenArgs & "") > 0 Then
Me.Filter = "[ProjIDfk] = " & Split(Me.OpenArgs, ";")(0) 'I use to have >1 field and had a need for "split" but kept as is
Me.FilterOn = True
Else
Me.Filter = "" 'this doesnt seem to turn the filter off and I want to be triggered if opening frmLetterOfCredit directly and not from frmProjects
Me.FilterOn = False
End If
Dec 07 2021 02:47 PM - edited Dec 07 2021 02:49 PM
SolutionHi,
1. Try to set the form's property FilterOnLoad to False. If that doesn't help, then
2. Instead of Filter="", try this in the OnLoad event of the form:
Me.FilterOn = False
Servus
Karl
*********
Access-Entwickler-Konferenz: https://www.donkarl.com/?AEK
Access DevCon: http://AccessDevCon.com
Access FAQ (de/en): https://www.donkarl.com