Mouse Down event not always working

birdieman

Well-known Member
Joined
Jan 13, 2016
Messages
551
I have the following code (mouse down) to select/highlight the entire contents of a textbox in a userform. I have this code to prevent the user from clicking in the middle of a formatted number and only changing certain digits (I want them to change the entire number). It works about 98% of the time, but sometimes I can still click on the very beginning of a formatted number ($45,000 for example) and enter a number BEFORE the $. I NEVER want the user to be able to do this.

1. Is there something about a FORMATTED number that allows me/user to enter a number in front of the $?

2. Does it have something to do with weird stuff that can occur in a textbox? My textboxes are NOT located in frames, but they are in labels.

3. Is there a way to alter the code to prevent this? Should I put in a Before Update event to recheck the number (i already have key press events to ensure a number is entered).

Code:
Private Sub TextBox137_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
  TextBox137.SelStart = 0
  TextBox137.SelLength = Len(TextBox137.Text)
End Sub
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).

Forum statistics

Threads
1,215,686
Messages
6,126,202
Members
449,298
Latest member
Jest

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top