Results 1 to 6 of 6
  1. #1
    Remster is offline Competent Performer
    Windows 10 Access 2010 64bit
    Join Date
    Sep 2010
    Posts
    317

    Text property of unbound textbox in form header


    Views: 6 Size: 392.0 KB">Database1.accdb


    The form in the attached database is bound to a table in which there are no records. The form has an unbound textbox in its header. The textbox's KeyDown event is set to display the textbox's text in a message box, but instead generates runtime error 2185 ("You can't reference a property or method for a control unless the control has focus"). Why is this, when the textbox clearly has the focus?*

    *I've tested this using Screen.ActiveControl, as well as the textbox's LostFocus event.

  2. #2
    Join Date
    May 2018
    Location
    Living in Scotland UK
    Posts
    1,557
    Hi

    I believe that the Control has to have data before you can SetFocus to it

    If you put data in the 1 record then on key down it pops up with OK

  3. #3
    ranman256's Avatar
    ranman256 is online now VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,521
    DONT use .Text property. That causes error.
    just use the contol name, me.txtbox ,to get the value.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,815
    An unbound control can definitely get focus with SetFocus.

    I tested KeyDown event with Text property and code works for me with UNBOUND form.

    However, output does not include character I just typed. Use Change event instead.

    Your form and code works when I set form AllowAdditions to Yes.

    But as ranman, suggests, don't use Text property and won't matter if form is bound or AllowAdditions is No.
    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
    Remster is offline Competent Performer
    Windows 10 Access 2010 64bit
    Join Date
    Sep 2010
    Posts
    317
    I do actually need to use the Text property in the present instance, because I need to establish the length of the contents of the textbox at the KeyDown stage, although I forgot to mention that I get the same error message whether I use KeyDown or Change.

    I've found a workaround, which is to set AllowAdditions to 'True' and hide all the controls, but it's odd that you're not getting the error message. I wonder if it's a version thing. I'm on Access 2010 at the moment.

    Edit: I've just re-read your post. You say (perfectly clearly!) that it works for you if the form is unbound. But I need the form to be bound.

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,815
    Edited my post some more, reread. I discovered the AllowAdditions issue.
    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.

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

Similar Threads

  1. Replies: 5
    Last Post: 01-07-2019, 01:51 AM
  2. Replies: 0
    Last Post: 10-06-2017, 06:22 PM
  3. Replies: 9
    Last Post: 11-05-2014, 09:23 AM
  4. Unbound textbox in bound form
    By Evilferret in forum Forms
    Replies: 5
    Last Post: 08-15-2012, 01:26 PM
  5. Replies: 1
    Last Post: 08-10-2008, 01:09 AM

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