• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 401
  • Last Modified:

Text control on Access form - double click highlights word

Hi
Have a text control on an Access 2003 form, cursor goes to the right of the last word.
Double clicking to the right of the last word highlights the word immediately to the left of the cursor.

In this application I dont want anything highlighted; is there any way I can turn off this behaviour. Have noticed if the last characater is a ) then it does not highlight the word in the parentheses. But I dont want parentheses closing off every last word in the text box. Unless I make it invisible but not sure how to do that. Maybe program a space after the last word. Am looking for an Access solution if there is one.

Many Thanks
0
ohgee
Asked:
ohgee
  • 5
  • 4
  • 2
1 Solution
 
SimonCommented:
You can set the 'enabled' property of the textbox to FALSE and its locked property to TRUE. If you want to make it invisible, set its visible property to false.

To get to the properties - Go to design view. right-click on the text control and choose properties from the contextual menu. Visibility is on the format tab, enabled and locked are on the data tab.
0
 
Leigh PurvisDatabase DeveloperCommented:
You can just cancel the Double Click event (assuming you don't need it for anything else - but the event procedure is still raised anyway).
The event procedure to cancel it is just:
Private Sub ControlName_DblClick(Cancel As Integer)
    Cancel = True
End Sub
0
 
ohgeeAuthor Commented:
Sorry, should have mentioned that I do use the double click event, for changing the text color. And would like to keep using double click for that. What I'm trying to prevent is the last word in the text box from highlighting on double click.

One possible solution might be to insert a space after the last letter in the last word so that the cursor does not butt up against the last letter. But not sure how to do this, or if there is a better solution.
0
Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

 
Leigh PurvisDatabase DeveloperCommented:
By "changing the text color" do you mean the property of the control? You don't want to use double click elsewhere to select a word - just not the last one?
A trailing space is just a partial solution. With the code it's the Event you're cancelling - not the event procedure. (The event is a UI action - it just also optionally first calls an event procedure - which can in turn cancel certain events).
Whatever code you did have in the DblClick event can remain there - just include the Cancel statement too.
Try it! :-)
Cheers
0
 
ohgeeAuthor Commented:
This form has two controls, sourced on two fields. One control has a click and double click event, and the other gets a yes or "" value from the double click / click event.

When user double clicks the control whose color changes, it places a "yes" value in the other control. When the user clicks the control, the yes changes to "".

Then have conditional formatting on the control with the click events; double click (yes) turns control text red, single click ("") turns it black.

So what I'm trying to achieve it for the text to change red,  but without the last word being selected. When the user selects the control the cursor goes to the end of line, ie it butts up against the last word. Then a double click turns all the text red but the last word is selected red; just looks sloppy and puts undue emphasis on that word. I suppose if the user placed the cursor against another word it would be highlighted, it's just usually the last one because that's where the cursor lands on gotfocus


0
 
SimonCommented:
In the code that sets the value of the 2nd textbox, try  Me!txtField.SelStart = Me!txtField.SelLength to set the selection start to the end of the field.
0
 
ohgeeAuthor Commented:
Placed this in the control's gotfocus event but cursor still butts up against the last word. Is there a way to completely prevent text selection via double click, for that one control.

Private Sub Article_Heading_GotFocus()
Me.Article_Heading.SelStart = Me.Article_Heading.SelLength
End Sub

Open in new window

0
 
Leigh PurvisDatabase DeveloperCommented:
So...
Have you tried the code as suggested?
It's amazingly quick to try things and you learn from it every single time - success or failure.
If I had a penny for every time I'd thought "Meh - I'll try it, I'll make it work"... I'd have like.. all these pennies.
As far as setting the position, I'd considered that naturally but
a) it's not as absolute as simply canceling the event
b) the fear of including it in the existing code should be just the same, as Canceling the event will have no more impact ;-)
c) as suggested, it wouldn't work. You'd need to set the start position to the width of the text of the control - not the Selected Width.
     Besides - the UI action of a double click would over-ride the position setting. (Unless you cancelled too ;-)
     You'd, more likely, set a flag variable in the double click event and then position in an event like Mouse Up .
     Even then, and using Me!txtField.SelStart = Me!txtField.Text, that would position at the end no matter where you double clicked.
     At a bareb minimum (still some holes), you'd end up with more like:
Private intPos As Integer

Private Sub txtField_DblClick(Cancel As Integer)
    intPos = Me!txtField.SelStart
End Sub

Private Sub txtField_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If intPos > 0 Then
        Me!Desc.SelStart = intPos
        Me!Desc.SelLength = 0
        intPos = 0
    End If
End Sub


Two variables would be better.
More fun - but I'd say go with the Cancel. ;-)
Private Sub txtField_DblClick(Cancel As Integer)
    Cancel = True
End Sub


Bear in mind what I said earlier. You can still include your other code in the event procedure!

Private Sub txtField_DblClick(Cancel As Integer)
    Me.OtherControl.ForeColor = 255
    Cancel = True
End Sub
Cheers.
0
 
ohgeeAuthor Commented:
I didn't try it, and the following code does work; good lesson lpurvis.
Thanks very much for staying with this, appreciate it.
Private Sub Article_Heading_DblClick(Cancel As Integer)
Me.True.Value = "yes"
Cancel = True
End Sub

Open in new window

0
 
ohgeeAuthor Commented:
Glad Lpurvis stayed with the problem because initially I did not follow the advice; good job.
0
 
Leigh PurvisDatabase DeveloperCommented:
No worries.
(Just remember... Try, try and try for fun! ;-)
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

  • 5
  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now