Results 1 to 4 of 4
  1. #1
    behnam is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2014
    Posts
    72

    How to check if textbox is empty for If statement.

    Hey all,



    i have a textbox called textbx1 and in this field the user enters four numbers representing the year. How can i say as an if statement if the year field is empty.

    I tried the following

    Code:
    If textbx1="" Then
    But this does not work.

    Thanks for your time.

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,549
    if isNull(textbx1) then

  3. #3
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    Your original attempt

    If textbx1="" Then

    is checking to see if there is a Zero-Length String in textbx1, The vast majority of the time, unless data is being imported from another program, a 'blank' Control in Access is Null, not a ZLS.

    ranman256's code

    if isNull(textbx1) then

    is checking for that Null.

    Many experienced developers will check for both...Zero-Length Strings and Nulls. This can be done a number of ways:

    If Nz(Me.textbx1, "") = "" Then

    and

    If (Me.textbx1 & "") = "" Then

    being just two of them.

    Linq ;0)>

  4. #4
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 7 64bit Access 2003
    Join Date
    Feb 2011
    Posts
    2,080
    And then there's always:

    if len(me.txtbx1 & "") > 0 then 'That gets the case of both Null and ZLS

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Clearing a textbox if its already empty
    By sevanty7 in forum Access
    Replies: 3
    Last Post: 05-17-2013, 11:27 AM
  2. Replies: 2
    Last Post: 04-23-2012, 10:13 PM
  3. Empty textbox crash
    By deepin125 in forum SQL Server
    Replies: 6
    Last Post: 04-03-2012, 02:55 PM
  4. check empty table
    By ramdandi in forum Queries
    Replies: 1
    Last Post: 12-20-2011, 04:31 PM
  5. Check if fields are empty
    By Doggfather22 in forum Forms
    Replies: 3
    Last Post: 12-02-2010, 11:03 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums