Verify if a text box = 0 is has nothing in it?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rhuns
    New Member
    • Jun 2010
    • 8

    Verify if a text box = 0 is has nothing in it?

    I am trying to verify if a text box is equal to 0 or is blank before the close button is pushed. The code works if the box equals 0 but not if it is blank. Can anyone help me with this. Here is the code:

    Code:
    Private Sub Command33_Click()
    UnusedHRS.SetFocus
    If UnusedHRS = 0 Or UnusedHRS = Null Then
        DoCmd.Close
    ElseIf UnusedHRS <> 0 Then
        MsgBox "There are still hours that are unaccounted for", vbInformation, "Staffmark"
        End If
    End Sub
  • Jerry Maiapu
    Contributor
    • Feb 2010
    • 259

    #2
    If I can understand you properly then try this:

    Code:
    Private Sub Command33_Click()
     If Me.UnusedHRS = 0 Or IsNull(Me.UnusedHRS) = True Then
      DoCmd.Close
       Else
           MsgBox "There are still hours that are unaccounted for", vbInformation, "Staffmark"
    Me.UnusedHRS.SetFocus
        End If
     End Sub
    If still not working replace
    Code:
    IsNull(Me.UnusedHRS)=True
    in line#2 with
    Code:
    Me.UnusedHRS)=" "
    Cheers..Hope this helps. Note: Using "Me" makes the code run faster.

    Jerry

    Comment

    • rhuns
      New Member
      • Jun 2010
      • 8

      #3
      Thanks Jerry, for the help the IsNull() worked perfectly!

      Comment

      • Jerry Maiapu
        Contributor
        • Feb 2010
        • 259

        #4
        Glad I could help

        Regards

        JM

        Comment

        • NeoPa
          Recognized Expert Moderator MVP
          • Oct 2006
          • 32633

          #5
          Code:
          Private Sub Command33_Click()
              UnusedHRS.SetFocus
              If Nz(Me.UnusedHRS, 0) = 0 Then
                  DoCmd.Close
              Else
                  MsgBox "There are still hours that are unaccounted for", vbInformation, "Staffmark"
              End If
          End Sub
          I would consider putting this code in the Form_Close() event procedure instead. Otherwise the form could be closed another way and it would work fine, thereby leaving hours unaccounted for.

          PS. Using IsNull() is also a perfectly reasonable approach. I prefer Nz(), but that's my personal choice.

          Comment

          Working...