Results 1 to 4 of 4
  1. #1
    djspod is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Mar 2015
    Posts
    164

    Testing Access form Textbox in VBA, not Null and String must be 10 or 11 Characters long

    Hi,

    I'm fairly new to VBA.

    I want to check that a user is entering the correct code into the form Textbox as they press a command button which decodes the product ticket code.

    The code string is always 10 or sometimes 11 characters long.

    Last 1 or 2 characters of the string are always digits and the 5 character of the string is always a W (IE: 4NXOWDHBC14)

    My decode VBA command button works fine.

    I now want to add in error handling for the following scenarios:

    • The user enters nothing in the textbox and presses the button
    • The users enters less than 10 characters
    • The user enters more than 11 characters.


    What's the best way of attacking this in a VBA process/programming way?


    I imagine with what I have already learnt in VBA, the Len function, IF and elseIf function and Msgbox's


    I can't seem to get the right combination in the right order, can anyone help or point me in the right direction please.

    Thanks








  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Numerous ways to attack this. You could test the length is 10 or 11 and only proceed if so, else throw up a message box. If you want to specifically test for them not entering anything:

    If Len(Me.TextboxName & vbNullString = 0 Then

    tests for both Null and a zero length string.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,407
    Code:
    Select case len(txtbox & vbnullstring)
        Case 0
            msgbox "Can't be blank!"
        case is > 11
            msgbox "too long"
        case is < 10
            msgbox "too short"
        case else
            msgbox "looks good!"
    end select

  4. #4
    djspod is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Mar 2015
    Posts
    164
    Both answers were brilliant and solved my problem!

    Thanks to both of you for taking the time to answer.

    I now have some more VBA knowledge



    Cheers Darren

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

Similar Threads

  1. Replies: 29
    Last Post: 10-03-2022, 11:06 AM
  2. Replies: 4
    Last Post: 03-11-2017, 09:48 PM
  3. Replies: 1
    Last Post: 02-25-2015, 04:40 PM
  4. Criteria string too long
    By bomich in forum SQL Server
    Replies: 2
    Last Post: 12-06-2012, 02:42 AM
  5. Replies: 3
    Last Post: 10-16-2011, 02:51 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