Results 1 to 4 of 4
  1. #1
    adamk1906 is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    May 2013
    Posts
    2

    Exclamation How to get the textbox name of the any textbox that is clicked

    Hello,

    I have 480 textboxes in my form. What I am looking to do, is that any time any of thest textboxes are clicked (or double clicked) I want to then get the name of that textbox saved into a variable.

    So I have created a public variable called tbName.

    What I need is this:

    - if the active control is a textbox then
    - tbname = active control name.



    It is important that I dont just take the active control name all the time as I want all controls other than textboxes to be igored. Secondly, under what event would I even put the code? Would it be the form Click event?

    Appreciate any feedback.

    Thanks
    Adam

  2. #2
    rzw0wr is offline I will always be a newbie
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2013
    Location
    Indiana
    Posts
    479
    Put the code under the click or double click event for all 480 text boxes.

    YourVariable Name = YourTextBoxName

    If you enlighten us as to what you want to do, I would think we could help you make it somewhat easier than using 480 variables and text boxes.


    Dale

  3. #3
    amrut is offline Expert
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2012
    Location
    India
    Posts
    616
    You have to decide which event you want to put the code depending on your requirements.
    In the form's module, put a function like
    Code:
    Function GetTextBoxName()
    GetTextBoxName=Screen.ActiveControl.Name
    Debug.Print GetTextBoxName
    End Function
    In design view, select all the text boxes.For ex. If you choose On Got Focus, then in the On Got Focus event
    put =GetTextBoxName()
    Hope above helps.

  4. #4
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    Depending on how critical this is to you, you may want to have a look at
    http://www.access-programmers.co.uk/...d.php?t=228040

    There is a database by ChrisO that has code to do what you are asking.

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

Similar Threads

  1. Replies: 2
    Last Post: 04-20-2013, 03:37 AM
  2. Replies: 8
    Last Post: 04-12-2013, 08:59 PM
  3. Copy textbox to textbox from query
    By zduffy in forum Programming
    Replies: 2
    Last Post: 11-08-2012, 02:36 PM
  4. Replies: 17
    Last Post: 02-08-2012, 10:06 AM
  5. Load textbox from another textbox
    By siddel77 in forum Programming
    Replies: 12
    Last Post: 08-30-2011, 01:46 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