Results 1 to 9 of 9
  1. #1
    matt_wpg is offline Novice
    Windows 10 Access 2016
    Join Date
    Mar 2017
    Posts
    20

    Check if unbound textbox is null

    Hi everyone,

    I am trying to check if an unbound text box is null using an if statement. I want to ensure that this box is filled in before the user saves the record (on a form).

    The name of the text box is "textbox1" For some reason iif(isnull[textbox1]) does not work, whereas this works perfectly on bound text boxes. Any ideas?



    Thanks!

    Matt

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,822
    Where are you using IIf()? Post full code. The posted syntax is wrong - missing parens for a start.

    What does 'does not work' mean - error message, wrong results, nothing happens?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    Bulzie is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    Nov 2015
    Posts
    1,463
    BeforeUpdate event on the form

    If isnull(me.textbox1) then
    Msgbox "textbox1 must have a value."
    me.textbox1.setfocus
    End
    End If

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,822
    Misspelled setforcus, remove the 'r'.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    matt_wpg is offline Novice
    Windows 10 Access 2016
    Join Date
    Mar 2017
    Posts
    20
    Thanks for the replies!

    I have an unbound textbox on a form that gets populated when a button is pressed on the form. However I don't want the user to forget to populate this textbox, therefore, in the "save record" button I have created, I have a macro in this button that is checking if the form is properly filled out. I am using the Macro builder (access 2010), and using the "if" function within this macro builder.
    For example, this functions correctly when the textbox is bound to a control source from the parent table. I can use the if function as follows: If(isnull([textbox2]) Then: Message box "please fill in textbox".

    Sorry I know the syntax doesn't make sense as I write it in this forum, but I am using the Macro builder. (easier to use for someone like me!).

    If i use this exact same method with an unbound text box, the user can leave the textbox empty because for some reason access thinks this empty box has text. it is almost as if unbound text boxes have invisible characters.

    If I run len([textbox1]) it returns "7". This is the amount of characters in "Unbound". So I tried if([texbox1] = "Unbound") Then: Message box "please fill in textbox". This also did not work...

  6. #6
    Bulzie is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    Nov 2015
    Posts
    1,463
    So does that button when pressed do some kind of calculation based on other fields on the record and puts the results in this unbound text box? If it is unbound, what do you do with the data when the record is saved or you move to a different record?

  7. #7
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,822
    The unbound textbox must have an empty string. Try:

    IIf([Textbox1] & "" = "", do this, else this)
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  8. #8
    davegri's Avatar
    davegri is online now Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,389
    I suspect that your textbox actually does contain 7 characters, probably on 2 lines. The textbox is not tall enough to show more than the first line, which probably is a carriage return. OR the textbox contains several space characters.
    To test this put the cursor at the beginning (left side) of the textbox and hit delete a dozen times. That would empty the textbox.
    If this test confirms the theory, you need to find out how the textbox gets populated.

  9. #9
    123noob is offline Novice
    Windows 10 Access 2010 64bit
    Join Date
    Jun 2017
    Posts
    14
    Is the textbox "enter key behavior" property set as default or new line in field? if new line in field, probably what said where the values could be on some other line.

    This should work imo where it would check for null or empty string field (like a space).

    if len(me.textbox1 & vbnullstring) = 0 then
    msgbox "Need to have a value in here"
    end if

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

Similar Threads

  1. Sum in unbound textbox
    By adeebarsad in forum Access
    Replies: 9
    Last Post: 03-22-2017, 09:01 AM
  2. Replies: 4
    Last Post: 03-11-2017, 09:48 PM
  3. Replies: 3
    Last Post: 03-26-2015, 06:50 PM
  4. unbound textbox to bound textbox
    By thescottsman92 in forum Access
    Replies: 3
    Last Post: 08-29-2013, 02:02 AM
  5. Replies: 8
    Last Post: 04-12-2013, 08:59 PM

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