Page 1 of 5 12345 LastLast
Results 1 to 15 of 65
  1. #1
    pdanes is offline Competent Performer
    Windows Vista Access 2007
    Join Date
    Sep 2019
    Posts
    208

    Textbox name into event parameter

    I have form with a large number of textboxes in an tightly packed array. It is a little difficult for the users to identify the correct row and column in which the control is located. What I am trying to do is use the MouseMove event to display the proper row and column in a label, which will change as the mouse travels over the array. The problem with that is that the event does not know which control has been rolled over. I could do it with a separate event routine for each control, but there are almost 350. That many routines would be awkward and a lot of work.

    I tried calling the same routine from each control, using the syntax =RunMouseOver(), and that works well, but I don't know who is calling. I then tried =RunMouseOver(Name), but Name returns the name of the form. I need the name of the textbox that is firing the MouseMove event. I have tried all sorts of experiments, like ControlName, Control.Name, and many others, all without success.

    Is there a way to get the name of the control into the call parameter?

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,716
    Here is a link to Event for multiple controls info that may be useful to you.
    Let us know your progress as your project evolves.
    Good luck.

  3. #3
    pdanes is offline Competent Performer
    Windows Vista Access 2007
    Join Date
    Sep 2019
    Posts
    208
    Thank you, there is a lot of good stuff there, but it is not quite what I'm looking for. All this stuff either addresses the form as a whole, or uses specific event procedures for each control. I don't want a separate routine for each textbox. I want one routine, with the name of the control as a parameter, and I'm trying to find out how to get the name of the control at the time the event is fired.

  4. #4
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,716
    OK. I've looked through my access links and found this, also by ChrisO. It may not be what you need but may have some concepts or ideas that you can adapt.

  5. #5
    pdanes is offline Competent Performer
    Windows Vista Access 2007
    Join Date
    Sep 2019
    Posts
    208
    That's closer - he is doing something quite similar to me, and it looks like he ran into a similar wall. What I've done as a stopgap is to write routine that modifies the MouseMove event to call the function with hard-coded parameters, and save the form that way. Not what I wanted, but it works. But I'm going to keep digging - I've needed stuff like this several times, and never gotten a satisfactory result. Always wound up with something that works, but isn't quite right. I'd like to find a correct path, or at least find out for sure that it isn't possible.

  6. #6
    apr pillai's Avatar
    apr pillai is offline Competent Performer
    Windows 10 Access 2007
    Join Date
    May 2010
    Location
    Alappuzha, India
    Posts
    209
    A Demo Database: MouseMove.zip is attached.

    1. Open Form3 (with several Text Boxes and a Label with the Name: Label0 on the Top) in Normal View.
    2. Move the Mouse over any Text Box.
    3. The Label on the Top will display the Text Box Name and the Mouse Coordinates X and Y values.
    4. Check the Code in Class Module ClsTxt.
    5. Check the Code of Form_Load() Event Procedure in the Form's Class Module.


    Each Class Object Instance (for each Text Box on Form3) is enabled, with the MouseMove Event Procedure and added to the Collection Object. Here Collection Object is used to hold all the ClsTxt Class Object Instance, instead of using an Array.
    The Class Object have an m_frm (Form) Property. Even though it is not used, in this case, for any purpose here, but if you would like to update a TextBox on the Form, other than the current Text Box, then it will be useful.

    http://www.msaccesstips.com/2018/10/...e-and-vba.html
    http://www.msaccesstips.com/2018/12/...ct-basics.html
    Attached Files Attached Files

  7. #7
    pdanes is offline Competent Performer
    Windows Vista Access 2007
    Join Date
    Sep 2019
    Posts
    208
    Quote Originally Posted by apr pillai View Post
    A Demo Database: MouseMove.zip is attached.

    1. Open Form3 (with several Text Boxes and a Label with the Name: Label0 on the Top) in Normal View.
    2. Move the Mouse over any Text Box.
    3. The Label on the Top will display the Text Box Name and the Mouse Coordinates X and Y values.
    4. Check the Code in Class Module ClsTxt.
    5. Check the Code of Form_Load() Event Procedure in the Form's Class Module.


    Each Class Object Instance (for each Text Box on Form3) is enabled, with the MouseMove Event Procedure and added to the Collection Object. Here Collection Object is used to hold all the ClsTxt Class Object Instance, instead of using an Array.
    The Class Object have an m_frm (Form) Property. Even though it is not used, in this case, for any purpose here, but if you would like to update a TextBox on the Form, other than the current Text Box, then it will be useful.

    http://www.msaccesstips.com/2018/10/...e-and-vba.html
    http://www.msaccesstips.com/2018/12/...ct-basics.html
    Wow! Many thanks - that is EXACTLY the behavior I was looking for. Since it doesn't do anything else, it looks to me like you made this entire thing just in response to my question. If so, thank you even more - such an effort just to help a complete stranger is admirable. You may be certain I will be studying this in great detail, and learning all the intricacies for future use.

    Thank you once again.

    Pete

  8. #8
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    maybe a simpler way:
    enter the following code in the form module
    Code:
    Function PassName()
    Dim ctl As Control
    
    For Each ctl In Forms!frmFormName.Controls
      If ctl.ControlType = acTextBox Then
      ctl.OnMouseMove = "=MyFunc(""" & ctl.Name & """)"
    End If
    Next
    End Function
    
    Public Function MyFunc(strControlName As String)
      MsgBox strControlName
    End Function
    In design view, select all the controls involved and enter = PassName() for the mouse move event. Compile & Save. Switch to form view and test. Works for me. Obviously you will want to do something other than have a message box.
    Wish I could take credit, but I got it from an Allen Browne reply. I love the idea of reassigning the mouse move event on the fly.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  9. #9
    pdanes is offline Competent Performer
    Windows Vista Access 2007
    Join Date
    Sep 2019
    Posts
    208
    Quote Originally Posted by Micron View Post
    maybe a simpler way:
    enter the following code in the form module
    Code:
    Function PassName()
    Dim ctl As Control
    
    For Each ctl In Forms!frmFormName.Controls
      If ctl.ControlType = acTextBox Then
      ctl.OnMouseMove = "=MyFunc(""" & ctl.Name & """)"
    End If
    Next
    End Function
    
    Public Function MyFunc(strControlName As String)
      MsgBox strControlName
    End Function
    In design view, select all the controls involved and enter = PassName() for the mouse move event. Compile & Save. Switch to form view and test. Works for me. Obviously you will want to do something other than have a message box.
    Wish I could take credit, but I got it from an Allen Browne reply. I love the idea of reassigning the mouse move event on the fly.
    Thank you for the tip. That is what I did when I was unable to get my original idea working. It does what I need, but I still want to be able to do it dynamically.

  10. #10
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    The problem with that is that the event does not know which control has been rolled over. I could do it with a separate event routine for each control, but there are almost 350.
    You lost me. What's not dynamic about that? It's one sub (routine) for 350 controls and it reports the name, which is what you asked for.

  11. #11
    pdanes is offline Competent Performer
    Windows Vista Access 2007
    Join Date
    Sep 2019
    Posts
    208
    Quote Originally Posted by Micron View Post
    You lost me. What's not dynamic about that? It's one sub (routine) for 350 controls and it reports the name, which is what you asked for.
    Sorry, it was a long day for me and I was a little groggy when I wrote that. 'Dynamic' was a poor choice of wording. Clearly, this method can be used with no design-time setting, and need not even be saved with the MouseMove property set, so it is fully dynamic.

    And actually, although both methods give me the behavior I wanted and solve my current problem, neither truly addresses the specific question I posed: Is there a way to specify the values of properties like control name, tooltip and others as a parameter in the event box at design time? As I wrote initially, =RunMouseOver(Name) works, to the extent that it passes the name of the parent FORM. I would like to pass other values, usually values specific to the control causing the event to fire.

  12. #12
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,716
    As I wrote initially, =RunMouseOver(Name) works, to the extent that it passes the name of the parent FORM. I would like to pass other values, usually values specific to the control causing the event to fire.
    Some questions conjure up different things to different people.
    Perhaps you could give us a concrete example(or a few) of your requirement/question/expectation.

  13. #13
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    neither truly addresses the specific question I posed: Is there a way to specify the values of properties like control name, tooltip and others as a parameter in the event box at design time?
    Maybe to you, but then I read in your original post
    "What I am trying to do is use the MouseMove event to display the proper row and column in a label," which could be interpreted as wanting a R1 C3 type of answer.
    but I ignored that because you also wrote
    "I need the name of the textbox that is firing the MouseMove event"

    then in post 3
    "I'm trying to find out how to get the name of the control at the time the event is fired."

    and now you're telling us that you posted that you wanted code to deal with other properties as in
    neither truly addresses the specific question I posed: Is there a way to specify the values of properties like control name, tooltip and others

    Where is any of that in your prior posts? Did you even test the code I wrote or did you just read it and draw your own interpretation of what it does? You like the complicated solution which as far as I can tell, does EXACTLY the same thing and EXACTLY what you asked for - as long as you leave tool tip text and such out of the request. If you don't then it doesn't either.

  14. #14
    pdanes is offline Competent Performer
    Windows Vista Access 2007
    Join Date
    Sep 2019
    Posts
    208
    I see no justification for your hostile tone. Both you and Apr Pillai provided something that worked, which I acknowledged, and thanked both of you.

    However, I was also curious about getting other properties of the calling control directly into the parameter of a custom function called from the MouseMove event, specifically in this case, the name of the control, rather than the name of the parent form. Where is any of that in my prior posts? In the original post that started this thread. The entire second paragraph details what I had done so far, and the single sentence of the third paragraph has exactly that question: "Is there a way to get the name of the control into the call parameter?"

    Yes, I am also curious about obtaining and passing other property values, besides the control name, which I did not specifically state in the original post – so sue me.

    I tested Apr's code, because he provided a complete database, with functioning form, and because he used some coding techniques with which I am not completely familiar. I did not test yours, because I did not need to – I read it. I did not "draw my own interpretation of what it does". I KNOW exactly what it does, because I read it, and I can follow it - I understand COMPLETELY every detail of what it does. As I wrote, it is what I had already done myself, because I was unable to get my initial efforts to work. I liked Apr's version because it showed me a technique that was new to me.

    Your suggestion is functional, and I said so immediately – you have nothing to crab about on that point. However, I would also like to learn something more along these lines. If you have something useful or intelligent to add to the discussion, I am more than happy to listen. But if you only want to berate me for not writing my question exactly the way you think I should have, then please go pester someone else.

  15. #15
    pdanes is offline Competent Performer
    Windows Vista Access 2007
    Join Date
    Sep 2019
    Posts
    208
    I'm not sure I can provide anything more concrete than that. As I wrote, =RunMouseOver(Name) calls the RunMouseOver function with the name of the parent form as the passed parameter. I wanted the name of the control, not the form. Both Apr Pillai and Micron showed me ways to accomplish what I needed, but not exactly in this way.

    =RunMouseOver(Name) calls the function and at runtime, evaluates [Name] to provide the name of the parent form. What I am looking for is a syntax that provides, at run time, some other values, in this specific case, the name of the control, and in general, other values, like ToolTip, Tag, or any other value that the system knows.

Page 1 of 5 12345 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Issues with change event of textbox
    By udigold1 in forum Programming
    Replies: 4
    Last Post: 03-27-2019, 08:39 AM
  2. Query with parameter from Form Textbox
    By Juan4412 in forum Queries
    Replies: 1
    Last Post: 07-10-2013, 02:33 PM
  3. Help with Onclick event to refresh textbox.
    By mikeone610 in forum Access
    Replies: 3
    Last Post: 02-07-2013, 03:58 PM
  4. Replies: 3
    Last Post: 05-07-2012, 12:17 PM
  5. How to call After update event to the textbox
    By pwalter83 in forum Forms
    Replies: 1
    Last Post: 12-20-2011, 11:16 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