Results 1 to 7 of 7
  1. #1
    CharissaBelle is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2016
    Posts
    81

    How do I keep people from putting a space in a first name field...


    I am working on a form that has a few text boxes to enter an employee name. FirstName, MiddleInitial, and LastName. I want to make sure that during data entry we avoid adding a space in the first name. It's long and drawn out to explain my reason. Is there an easy way to not allow a space in the FirstName field? I can't even think of the language to explain what I am wanting to do. Hope this is somewhat clear. Thank you

  2. #2
    Micron is offline Virtually Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    On the BeforeUpdate event for the control, use the Trim function to remove leading or trailing spaces. If you mean anywhere, including in between characters, use the Replace function.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #3
    CharissaBelle is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2016
    Posts
    81
    Quote Originally Posted by Micron View Post
    If you mean anywhere, including in between characters, use the Replace function.
    I don't have anything to replace it with. I'm hoping that somehow I can have a message box pop up if there is a space to tell the person spaces aren't allowed. Is there anything like that?

  4. #4
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    You can use the Before Update event of the First Name textbox to check for spaces using the Instr function, and if space(s) are found, give the user an error message, and cancel the Update:

    Code:
    If instr(me![firstName], " ") > 0 then
      msgbox "First name cannot contain a space"
      Cancel = -1
      exit Sub
    Endif

    Replace firstname with the actual name of your first name text box.

  5. #5
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,397
    I don't have anything to replace it with
    you replace it with a zls (zero length string)

    firstname=replace(firstname," ","")

  6. #6
    CharissaBelle is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2016
    Posts
    81
    Thanks. I'll try that and see how it goes.

  7. #7
    Micron is offline Virtually Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    Quote Originally Posted by Ajax View Post
    you replace it with a zls (zero length string)

    firstname=replace(firstname," ","")
    Thanks; that's exactly what I had in mind.

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

Similar Threads

  1. Replies: 13
    Last Post: 11-30-2016, 09:59 AM
  2. Replies: 4
    Last Post: 05-22-2015, 05:52 AM
  3. Replies: 1
    Last Post: 06-09-2013, 10:40 AM
  4. Putting an Expression in a Field Box
    By MWB in forum Queries
    Replies: 4
    Last Post: 11-02-2010, 06:58 AM
  5. Replies: 0
    Last Post: 12-28-2009, 12:14 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