Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

input mask regarding capital letters

Status
Not open for further replies.

jgeneie

Technical User
Feb 20, 2002
41
0
0
SG
hi all,

juz a little question on input mask. Can i use input mask to force the first letter of a word to become a capital letter when a user enters in a txt box??

thanks

 
Easy as pie. Given a 10-character text field,
use
Code:
>L<?????????
as the input mask. DO NOT set anything in the format property.

You will need a ? placeholder for the &quot;length-1&quot; number of characters, in my example, 9


Remember, you're unique - just like everyone else
You're invited to visit another free Access forum:
or my site,
 
What do you do if you don't know the exact length of the value coming in? can you still use the input mask?
 
Maboo, that's the problem with setting an INPUT MASK - it presumes an exact character input. If you don't know how long the input strings will be, you'll probably need to use a special function like STRCONV() or an 3rd party solution such as GeekInGlasses suggested.

You can use STRCONV on the BEFORE_UPDATE event of a control to convert the input:

MyField = strConv(MyField, vbProperCase)

Remember, you're unique - just like everyone else
You're invited to visit another free Access forum:
or my site,
 
There must be a better way than this!? Can't you just examine the first letter of a string and if it isn't a capital convert it to the capital equivalent?
 
You don't need to know the exact number of characters - just use:

>L<??????????????????? for a 20 character field. The &quot;?&quot; is optional, so you don't have to enter that many characters. If you enter &quot;test&quot;, it will display &quot;Test&quot;.

This is the easiest way to do this.

Of course, the other option is to let them put data in in either upper or lower case, and just convert it when you display it in a form or report - but that's more work.




 
Place in the after update of your textbox control

Dim strname As String
Dim strname1 As String

strname = Left(Me.Text0, 1)
strname1 = UCase(strname)
Me.Text0.Value = strname1 & Mid(Text0.Value, 2)

This will change the first letter to capital. hope it helps.
 
re GDGarth's post - yeah, this seems to work fine in A2K - but I swear it didn't work this way in A97..hmmm..

It is obviously the easiest way to do it. Which is what I would have used...had it worked in A97...I only have A2K loaded on the beast now, so I can't go back and test (or should I say Test) it...

Good point.

Jim Me? Ambivalent? Well, yes and no....
Another free Access forum:
More Access stuff at
 
I use '97, and it worked fine on my system (I tried it before I posted).
 
This function I wrote a few years ago converts all characters in a string to UCase, but ignores characters already in UCase, so can handle say:

Function RealProper(varString As Variant) As Variant
Dim i As Integer
Dim strString As String
Dim strCurrChar As String, strPrevChar As String
If IsNull(varString) Then
Exit Function
End If
strString = CStr(varString)
For i = 1 To Len(strString)
strCurrChar = Mid$(strString, i, 1)
Select Case strPrevChar
Case &quot;A&quot; To &quot;Z&quot; 'ignore characters that are already UCase
Case &quot;a&quot; To &quot;z&quot;
Mid(strString, i, 1) = LCase(strCurrChar)
Case Else
Mid(strString, i, 1) = UCase(strCurrChar)
End Select
strPrevChar = strCurrChar
Next i
RealProper = CVar(strString)
End Function


msgbox RealProper(&quot;the AA is better than the RAC says mr mcDonald!)

This would return: &quot;The AA Is Better Than The RAC Says Mr McDonald!&quot;

vbProperCase would return &quot;The Aa Is Better Than The Rac Says Mr Mcdonald!&quot;

Happy xmas to you all.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top