How to check for empty string?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • robin27th
    New Member
    • Aug 2010
    • 11

    How to check for empty string?

    Hi,
    I am very new to access. I am asking something basic.

    Code:
    Private Sub Command12_Click()
        Dim strAbc As String
        strAbc = "a"
        MsgBox IsNull(strAbc)
        MsgBox IsEmpty(strAbc)
    End Sub
    How to check if variable strAbc has a value/is not an empty string? I tried isNull and isEmpty and both returns false whether strAbc is assigned "" or "a".

    Thanks,
    Robin
    Last edited by Dormilich; Aug 17 '10, 08:56 AM. Reason: Please use [code] tags when posting code
  • MikeTheBike
    Recognized Expert Contributor
    • Jun 2007
    • 640

    #2
    Hi

    You could try this

    MsgBox strAbc <> ""

    ??

    MTB

    Comment

    • munkee
      Contributor
      • Feb 2010
      • 374

      #3
      I use the following to check for null and zero length string of a control. Just replace control for your string variable.

      Code:
      Len(Nz(Me.controlname, "")) = 0
      or you can just use the straight
      Code:
      len(string) < 1

      Comment

      • NeoPa
        Recognized Expert Moderator MVP
        • Oct 2006
        • 32661

        #4
        Robin, It's important to know what you are dealing with when making such a check. As yours clearly states it is a string variable, then the correct way to check it would be as Mike has suggested - (strABC = "").

        On the other hand, form controls are objects that may contain Null. Checking form controls should be done using IsNull() instead - (IsNull(Me.txtA BC)). Controls with no data entered are never empty strings. Nz() may be used for simplifying usage of the control's value, but is not a good way to test if anything has been entered.

        Comment

        Working...