Results 1 to 10 of 10
  1. #1
    Middlemarch is offline Competent Performer
    Windows 10 Access 2019
    Join Date
    Mar 2015
    Posts
    365

    This must be right, but why?


    Form has one textbox.
    Code:
    Private Sub Form_Open(Cancel As Integer)
        txtEComment = "why is this highlighted"
    End Sub
    Forecolor is black, backcolor is white. But it's reversed showing selected or Highlit until the textbox is clicked. Why is that?
    Should it not just open and show the text in the colors assigned?

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,921
    This textbox gets focus when form opens?
    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
    Middlemarch is offline Competent Performer
    Windows 10 Access 2019
    Join Date
    Mar 2015
    Posts
    365
    Not sure if you're asking me or telling me, but seems you'd not want it to be selected, but where to move the focus if there's no other control ?
    Can you set Focus just to the Form ?

  4. #4
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Office 365
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,977
    Yes it is because the textbox has focus. Setting the focus to the form itself won't help.
    However you can move the cursor to the start or end of the textbox to solve this

    Code:
    Private Sub Form_load()
    
    Me.Text0 = "test"
    
    Me.Text0.SetFocus
    Me.Text0.SelStart = 0 'move cursor to start
    'Me.Text0.SelStart=Len(Me.Text0) 'move cursor to end
    End Sub
    BTW I sent you a PM a few weeks ago (30 Oct) but didn't get a reply. Can you have a look please
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  5. #5
    Middlemarch is offline Competent Performer
    Windows 10 Access 2019
    Join Date
    Mar 2015
    Posts
    365
    Hi @Colin, that stops the text beig selcted nut the cursor at the start doesn't seem right eother. If anywhere at the end of text is more logical.
    Access sure is strange at times, ok so a Form with one control gives focus to that contoel. but why select the text as well ?
    And if it has focus, why is the command Me.Text0.SetFocus needed ?
    Sorry for missing your PM but there's nothing in my inbox.

  6. #6
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Office 365
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,977
    You have to explicitly set the focus to the control to use SelStart
    It may be that Access is actually setting the focus to the form but as the form only has the one control, perhaps that means the textbox is selected without actually having focus????

    Apologies- the PM was sent to another forum member with a fairly similar name - not to you!
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  7. #7
    davegri's Avatar
    davegri is offline Excess Access
    Windows 11 Access 2019
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,412
    When I don't want anything visible selected when a form opens, I create a dummy text box, txtDummy, set its height and width to zero and its tabindex to 0.
    After form opens, you have to tab or click with mouse to see the cursor.

  8. #8
    Middlemarch is offline Competent Performer
    Windows 10 Access 2019
    Join Date
    Mar 2015
    Posts
    365
    @davegri I vaguely remember that now, but thought it a hack and there must be something better.
    Something in properties would have been helpful.
    But if it's the only way....

  9. #9
    davegri's Avatar
    davegri is offline Excess Access
    Windows 11 Access 2019
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,412
    Quote Originally Posted by Middlemarch View Post
    @davegri I vaguely remember that now, but thought it a hack and there must be something better.
    Something in properties would have been helpful.
    But if it's the only way....
    If you get other solutions that you like better, you then have other choices.

  10. #10
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Office 365
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,977
    It can also be done without code from Access Options...Client Settings..,Behavior entering field.
    There are 3 choices - Select entire field, go to start of field, go to end of field. Only the first choice will highlight the textbox contents.
    This achieves the same result as using SelStart BUT it is a per user setting
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

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

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