Forum Discussion

Tony2021's avatar
Tony2021
Steel Contributor
Dec 07, 2021
Solved

OpenArgs

 

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

  • arnel_gp's avatar
    arnel_gp
    Steel Contributor

    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