locked
Opening Form from SubForm RRS feed

  • Question

  • So I have a CustomerF form with a subform that shows all of the systems. I am able to open the form associated with the subform when I click on it with 

    Private Sub Text3_Click()

            DoCmd.OpenForm "SystemsF", , , "SystemsID =" & Me.SystemsID

    End Sub

    (Text 3 being the cell I click)

    I would like to have it go to a new systems form when I click an empty cell, or at the very least, do nothing. Now, when I click an empty cell, it gives me an error. I tried 

    Private Sub Text3_Click()

            If Me.SystemsID = Null Then

                    DoCmd.OpenForm "SystemsF" , , , acNewRec

            Else

                    DoCmd.OpenForm "SystemsF", , , "SystemsID =" & Me.SystemsID

    End Sub

    This didn't work. And I think I know why; I assume because even the first one filters the records to only show that specific one. I have no idea how to resolve this. I've tried doing a pass, and tried omitting the If of it being Null all together but none of that worked. Any advice would be appreciated. 

    Thanks!

    Friday, May 4, 2018 3:41 PM

All replies

  • Change the line:

        If Me.SystemsID = Null Then

    to:

        If IsNull(Me.SystemsID) Then

    Null is not a value but the absence of a value, so cannot be 'equal to' anything, even to Null.  The result will always be Null, neither True nor False.


    Ken Sheridan, Stafford, England

    Friday, May 4, 2018 3:50 PM
  • I tried that and it's opening my SystemsF form but not going to a new record. Is there something wrong with my code?:

      DoCmd.OpenForm "SystemsF" , , , acNewRec 

    I tried it with one less comma and it still didn't work how it was supposed to...

    Friday, May 4, 2018 7:21 PM
  • Forget about the number of commas, just name the arguments.  And the constant for the DataMode argument to open a form at a new record is AcFormAdd:

        If IsNull(Me.SystemsID) Then
            DoCmd.OpenForm "SystemsF", DataMode:=acFormAdd
        Else
            DoCmd.OpenForm "SystemsF", WhereCondition:= "SystemsID =" & Me.SystemsID
        End If

    Ken Sheridan, Stafford, England

    Friday, May 4, 2018 9:20 PM