propercase doesn't work

Pookiemeister

Well-known Member
Joined
Jan 6, 2012
Messages
563
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
I do not understand why this code won't work in my textbox on Access userform.

VBA Code:
Option Compare Database

Private Sub FirstName_Change()
   Me.FirstName.Value = StrConv(Me.FirstName.Value, vbProperCase)
End Sub
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
What did you expect this to do? this code won't work

From Microsoft textbox change

Changing the data in a text box or combo box by using the keyboard causes keyboard events to occur in addition to control events like the Change event. For example, if you move to a new record and type an ANSI character in a text box in the record, the following events occur in this order:


KeyDownKeyPressBeforeInsertChangeKeyUp

The BeforeUpdate and AfterUpdate events for the text box or combo box control occur after you have entered the new or changed data in the control and moved to another control (or clicked Save Record on the Records menu), and therefore after all of the Change events for the control.
 
Upvote 0
Whatever is typed into the textbox. I wanted to capitalize the first letter that is entered.
 
Upvote 0
I do not understand why this code won't work in my textbox on Access userform.
Because at the moment you type a character the control value is null.


When does that event trigger? Because I don't see doing anything.
That was explained in post 2.

If you cannot use AfterUpdate then IMO you will have to use a key event for the control - possibly KeyUp. You'll have to add code to move to the end of whatever is typed in because the cursor will jump to the beginning of the word when you update after every key stroke - probably will look funny to anyone watching. Also, I think you will have to use the control's Text property because of the Null thing. Best to let the value update when focus moves off of the control.
 
Upvote 0
Actually, it looks OK on my laptop. Something like

VBA Code:
Private Sub Text0_KeyUp(KeyCode As Integer, Shift As Integer)
Me.Text0.Text = StrConv(Me.Text0.Text, vbProperCase)
Me.Text0.SelStart = Len(Me.Text0.Text)
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,614
Messages
6,120,520
Members
448,968
Latest member
Ajax40

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