Capitalizing the First character of a name using input mask

n_m

New Member
Joined
May 18, 2005
Messages
2
Hi,

Am trying to do the above & am finding that '> ' function capitalizes all the letters - is there any way of forcing caps on the first character?

Thanks in advance
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
Are you sure you mean input mask?
 
Upvote 0
Are you 100% sure?

When I put > in the Input Mask property of a field in a table or form Access doesn't allow me to enter any data?

If I put > in the Format property of a field in a table or form then the data entered is capitalized.
 
Upvote 0
I'd would suggest you use a function for this. Such as:-

SELECT UCase(Left([FieldName,1)) & LCase(Right(FieldName,Len([FieldName])-1)) as FirstLetterOnly
FROM yourTable;
 
Upvote 0
Sorry, should have said SQL and not function. This is the function.

Public Function Capitalize(str As String)

Dim i As Integer
Dim wasspc As Boolean

wasspc = True

For i = 1 To Len(str)
If wasspc Then
str = Left$(str, i - 1) & UCase(Mid(str, i, 1)) & Right(str, Len(str) - i)
End If
wasspc = IIf(Mid(str, i, 1) = " ", True, False)
Next i

Capitalize = str

End Function
 
Upvote 0
Tanis

Do you really need a loop?
Code:
Public Function Capitalize(str As String) 

     Capitalize = UCase(Left(str, 1))  & LCase(Mid(str, 2))

End Function
 
Upvote 0
Hi Norrie. No, the loop is not necessary. However, in my defence it was one of the first functions I wrote, and as it worked I saw no reason to change it. Point taken though.
 
Upvote 0
You could also try this input mask:

Code:
>L<?????????????????? (Holds up to 18 chars)
The > forces all following text to be uppercase. The L requires a letter. The < forces all following text to be lowercase. Each ? allows any letter or no letter, and there is one fewer question mark than the maximum number of letters you want to allow in the field (19, including the leading capital letter). The Field Size setting must be greater than this maximum.

HTH,
CT
 
Upvote 0
Yeah, that's fine if you can guarantee that the field length does not exceed the number of characters of the input mask. That is why I use a function. Horses for courses. Whatever suits you best.
 
Upvote 0

Forum statistics

Threads
1,221,499
Messages
6,160,164
Members
451,628
Latest member
Bale626

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