SOLVED

OpenArgs

Steel Contributor

 

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.   

2 Replies
best response confirmed by Tony2021 (Steel Contributor)
Solution

Hi,

 

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

@Tony2021 

 

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

 

 

1 best response

Accepted Solutions
best response confirmed by Tony2021 (Steel Contributor)
Solution

Hi,

 

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

View solution in original post