Forum Discussion

Tony2021's avatar
Tony2021
Steel Contributor
Oct 03, 2024

Open Form when OpenArgs is Null

Hello Experts,

 

I usually open a form with OpenArgs but I now want to be able to open the form on its own (not from another form) and add a record without using the OpenArgs.  I still need to retain the OpenArgs functionality though when I do open the form from another form and using OpenArgs. 

 

I currently get an "Invalid Use of Null" error 94 when I try to open the form on its own.  

 

How would I modify the below if OpenArgs is Null?  

 

Private Sub Form_BeforeInsert(Cancel As Integer)

        Me.txtPrjIDfk = Split(Me.OpenArgs, ";")(0)
End Sub

 

here is the error on the form.  I get it when I try to add a new record and OpenArgs are Null (its says 0 in below and I assume that is Null). 

 

 

thank you

  • Tony2021 check if it IsNull()

     

    Private Sub Form_BeforeInsert(Cancel As Integer)

           If NOT IsNull(Me.OpenArgs) Then

               Me.txtPrjIDfk = Split(Me.OpenArgs, ";")(0)

          Else

              'do another thing

         End If
    End Sub

  • arnel_gp's avatar
    arnel_gp
    Steel Contributor

    Tony2021 check if it IsNull()

     

    Private Sub Form_BeforeInsert(Cancel As Integer)

           If NOT IsNull(Me.OpenArgs) Then

               Me.txtPrjIDfk = Split(Me.OpenArgs, ";")(0)

          Else

              'do another thing

         End If
    End Sub

    • Tony2021's avatar
      Tony2021
      Steel Contributor
      Nice! that worked perfectly. thank you Arnel. Nice to see you again.
  • Ken_Sheridan's avatar
    Ken_Sheridan
    Brass Contributor

    Then fact that you are calling the Split function suggests that you are passing multiple values into the form.  You might like to take a look at Args.zip in my public databases folder at:

     

    https://1drv.ms/f/c/44cc60d7fea42912/EhIppP7XYMwggESpAAAAAAABaDKZCllSuweYBPJ5zKa3cg

     

    This little demo file illustrates the use of a function, originally written by Stuart McCall, and later amended by me to allow named arguments to be passed.  The function tokenises the string expression with high ASCII characters, allowing you to include low ASCII characters like the semi-column, in the values passed.

Resources