Results 1 to 3 of 3
  1. #1
    tylerg11 is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Sep 2011
    Posts
    200

    SelStart not accounting from spaces?

    Hi All,



    So I have a textbox in the header of one of my forms. For it's On Change event I have it filtering the form based on whatever is entered in the textbox. This works great. However, after the filter is re-applied after each "change", I have SelStart code to place the cursor back in the textbox. Problem is that SelStart does not seem to be accounting for any spaces in the textbox, and continues to place the cursor after the last character - not space - in the textbox. Here's the code:

    Code:
        strLastName = Nz(Me.txtLastName.Text, "")
        
        Me.Filter = "CONTACT_LASTNAME like '%" & strLastName & "%'"
        
        Me.FilterOn = True
        
        Me.txtLastName.SelStart = Len(strLastName) + 1
    For example, if I entered "An ", the Len() will return a 3, but when it goes to place the cursor back in the textbox, it basically seems to remove that trailing space. Therefore, the user is not allowed to insert spaces.

    Any ideas??

    Thanks!

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    Appears to be the nature of textbox to drop trailing spaces. My testing with AfterUpdate event shows the Len results in 2 instead of 3. The space is dropped immediately and not included in the Len count. Testing Change event shows that the first time I enter "An " characters into box the Len count is 0 after each character. If I repeat "An " the count is 2. I have to null the box and the count will be 0 again. Not understanding this behavior and can't reproduce your results. Sorry.


    Don't really need the Nz function, just concatenate an empty string.

    strLastName = Me.txtLastName & ""

    This is code in Access VBA? The default property of data controls is Value and is assumed if not specified. Text appears to produce the same result, just not necessary. I would have used the * wildcard but if % is working, fine.
    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
    help_me_with_access is offline help_me_with_excel
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    262
    dropping whitespace from values is a default behavior in access. as far as I know, all whitespace that appears after the last byte in any input is truncated.

    but in all honesty, that seems to be decent behavior to me. i've never seen this question asked before, actually.

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

Similar Threads

  1. Accounting database
    By Ray67 in forum Database Design
    Replies: 1
    Last Post: 04-10-2012, 09:45 PM
  2. Accounting System Control
    By Shades in forum Access
    Replies: 0
    Last Post: 12-08-2011, 10:29 AM
  3. SelStart problem
    By ybg1 in forum Access
    Replies: 2
    Last Post: 11-14-2010, 12:50 AM
  4. Accounting Template
    By mastromb in forum Access
    Replies: 4
    Last Post: 02-24-2010, 10:36 AM
  5. Deleting Spaces
    By grgerhard in forum Import/Export Data
    Replies: 2
    Last Post: 04-30-2006, 06:42 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