One checkbox working one check box not -- same code

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • SeadooRider
    New Member
    • Jan 2013
    • 48

    One checkbox working one check box not -- same code

    I have two checkboxes on my form. What I'm trying to do is if the checkbox is checked, a related field must have an entry. One checkbox is bringing up the msgbox, the other is not.

    First code works:
    Code:
    Private Sub CkSAOntwkPOC_AfterUpdate()
    If CkSAOntwkPOC = -1 And Pref_DSN = "" Then
    Cancel = True
    MsgBox "this record..."
    Pref_DSN.setfocus
    end If
    End Sub
    Second Code only works if the And... is left off
    Code:
    Private Sub CkDTSPO_AfterUpdate()
    If CkDTSPO = -1 And PhoneListName = "" then
    Cancel = True
    MsgBox "This record requires..."
    PhoneListName.setfocus
    End If
    End Sub
    Like I said, if I take the -- And PhoneListName = "" off, it works.

    What could be the difference?

    Thx
    Jason
  • SeadooRider
    New Member
    • Jan 2013
    • 48

    #2
    Also, the second one works if I put And PhoneListName = "1" and then if there is a 1 in the field it works correctly.
    So, it has something to do with the ""

    Comment

    • Rabbit
      Recognized Expert MVP
      • Jan 2007
      • 12517

      #3
      Are you sure the PhoneListName is a blank string and not a null? A null can look like a blank string but they are not the same thing. To cover both possibilites, you should use
      Code:
      Nz(FieldName, "") = ""
      Where the Nz function converts nulls to the blank string.

      Comment

      • SeadooRider
        New Member
        • Jan 2013
        • 48

        #4
        Hmm, never seen that before. I had tried Is Null but that didn't work either. the Nz thing worked great.

        thx

        Comment

        • Rabbit
          Recognized Expert MVP
          • Jan 2007
          • 12517

          #5
          Is Null is a SQL only thing. The equivalent in VBA code is the IsNull() function.

          Comment

          • SeadooRider
            New Member
            • Jan 2013
            • 48

            #6
            Ahh, good to know, I didn't try IsNull().

            Comment

            Working...