Page 2 of 2 FirstFirst 12
Results 16 to 23 of 23
  1. #16
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    probably work in the exit event as well - my reading of the event is the code runs, then focus is lost



    you can adapt the code to work in the dblclick event as you have your version

  2. #17
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    I would have interpreted it the other way around. Since such things are all about being event driven, makes sense to me that the event has to happen before anything can execute the code. In that case, code shouldn't run until focus is lost. Seems not to be the case, or this is some sort of anomaly.

    EDIT - my reasoning for that:
    When the focus leaves a control on a form...the Exit and LostFocus events occur in this order: Exit LostFocus
    https://support.microsoft.com/en-us/...86553682f9#bm1
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #18
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    Between waiting for stain and finish to dry between coats, watching the world series and listening to the constant rain I stuck with this. Got up to about 100 lines of code, dealing with the myriad of issues that would arise. Suppose the string was The old dog slept under the oak tree all day long. The control value is

    <div><font color=red>The </font>old <strong>dog</strong> slept under <font color="#4472C4"><strong>the</strong></font> oak tree all day long</div>

    If cursor is at T in The, Selstart is 1 but it's actually about the 21st character in the control value. I mentioned this sort of thing in a prior post, not sure it was recognized by all. So my approach was (as brief as possible)
    - parse out the tags and add them to a collection, which requires a function to return whether or not a character was < or not and somewhat complex string functions such as Mid(strRTF, x, y - x + 1)
    - inner loop the function until the next <, concatenate as we go and put that into a plain text collection, all the while updating the string checking position
    - oh, and as we inner loop, check if z = selstart (can't use x or y). If so, calculate where to put the * because it's not SelStart as already noted
    - I'll just mention that once * is inserted, guess what has happened to the length of the string?
    - I know the max key number because I've been incrementing its variable so loop over the collections up to that value.
    Col1 might have (e.g.) keys 1,2,4,7... while Col2 has 3,5,8 so you raise an error trying to get member 3 from Col1, thus resume next and it will get it from Col2 & vice versa
    - concat all back together and make control = this concatenated string



    Seems to work. Then I had an idea and what I ended up with, instead of over 100 lines of code is this:



    Code:
    Private Sub Text6_DblClick(Cancel As Integer)
    SendKeys "+{8}", False
    DoEvents
    
    End Sub
    Such is life.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  4. #19
    orange's Avatar
    orange is offline Moderator
    Windows 10 Office 365
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    Nothing better than persistence and finding a "simpler" solution.
    Looks good!

  5. #20
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    just hope the OP doesn't insist on using a button

  6. #21
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    Quote Originally Posted by Ajax View Post
    just hope the OP doesn't insist on using a button
    Based on my testing re Lost Focus vs Exit. Not to reopen that debate, but if I put the cursor at position 11 in the control value (string) Exit event msgbox reports SelStart as 11. The long version of the code would handle that:
    as we inner loop, check if z = selstart
    Z is incremented only while looping over regular text, not rtf tag text so its value is less than x (the position within the control value, which is the whole enchilada).

    This is one of those rare times where I'd strongly favour SendKeys.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  7. #22
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    must admit, the requirement is a strange one and as has been suggested I suspect there is more to this than has been revealed. I spent some time a few years back trying to find a way to get the cursor position of a richtext field and the way I illustrated was the best I could do. I was creating an 'access studio' app (similar functionality to SQL server management studio) and was using richtext for formatting sql code both in terms of layout and also colour for keywords. I was trying to enforce the inserting of characters such as carriage return, closing brackets etc according to the rules I set up but gave up on that in the end!

    But I didn't think of using sendkeys - I might dig out the app and see if I can make that work for me now

  8. #23
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    Perhaps start a thread if you're successful and maybe link to this one. Might be of interest to someone. I for one wonder if you can simply SendKeys for any character you need, and would it be enough to insert ( or would you have to insert &lpar; ).

    I think my long code version would deal with < as that character is actually not part of the string value, although it's what you'd see in the form control. That character is shown as &lt; so the loop should keep "&lt;" in the string that makes up one member of the plain text collection. At least that's my theory. I might test to see if it remains as " < " in the control.

    Forgot so say - you might be interested in this sort of info
    https://www.lookuptables.com/text/html-character-codes
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

Page 2 of 2 FirstFirst 12
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 15
    Last Post: 02-17-2019, 06:19 PM
  2. Replies: 9
    Last Post: 02-06-2019, 05:49 PM
  3. Replies: 6
    Last Post: 01-13-2017, 08:54 AM
  4. Replies: 2
    Last Post: 01-04-2016, 04:44 AM
  5. Bold Field by Cursor Position
    By Rawb in forum Forms
    Replies: 4
    Last Post: 02-08-2011, 08:03 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