input mask for capitalization of 2 words in one field

G

Guest

I need an input mask for an Access 2000 form to capitalize the first letter
of 2-word last names. I must retain the option of entering a one-word last
name.
 
J

John Vinson

I need an input mask for an Access 2000 form to capitalize the first letter
of 2-word last names. I must retain the option of entering a one-word last
name.

An Input Mask is not capable of doing this. It's a very limited tool.

You can use VBA code in the AfterUpdate event of the textbox to do
this: something like

Private Sub txtLastName_AfterUpdate()
' only capitalize values that are all lower case to begin with
' e.g. leave "van Camp" and "McCarthy" and "de la Cruz" untouched
If StrComp(Me!txtLastname, LCase(Me!txtLastName), 0) = 0 Then
Me!txtLastName = StrConv(Me!txtLastName, vbProperCase)
End If
End Sub

The StrConv() routine will convert "riki tiki tavi" to "Riki Tiki
Tavi", capitalizing each word.

John W. Vinson[MVP]
 
G

Guest

Thank you for your quick response John. I have not as yet delved into VBA
(I've done VBScript) but I'll give it a try. I wish Input Masks used wild
cards! Then you could do somthing like: >L<* >L<* right? Thanks again.
Catherine
 
G

Guest

John,

I tried your language in my database (Access 2000), tried to modify it, but
continue to get errors. The following is my current Event Procedure.

***************************
Private Sub FirstName_AfterUpdate()
Dim t_FirstName As String
t_FirstName = UCase(Left([FirstName], 1)) & Mid([FirstName], 2, 20)
Me.FirstName = t_FirstName
End Sub
Private Sub LastName_AfterUpdate()
Dim t_LastName As String
t_LastName = UCase(Left([LastName], 1)) & Mid([LastName], 2, 20)
Me.LastName = t_LastName
End Sub
****************************
Like Catherine, I need to allow Last Names to be left unchanged if the user
types both lower and upper case (i.e. de la Teja), but capitalize if only one
word in the last name (i.e. anderson to Anderson).

Any help here??
Thanks
 
J

John Vinson

John,

I tried your language in my database (Access 2000), tried to modify it, but
continue to get errors. The following is my current Event Procedure.

***************************
Private Sub FirstName_AfterUpdate()
Dim t_FirstName As String
t_FirstName = UCase(Left([FirstName], 1)) & Mid([FirstName], 2, 20)
Me.FirstName = t_FirstName
End Sub
Private Sub LastName_AfterUpdate()
Dim t_LastName As String
t_LastName = UCase(Left([LastName], 1)) & Mid([LastName], 2, 20)
Me.LastName = t_LastName
End Sub

Well, that bears no resemblance whatsoever to the code that I posted.
If the code I posted doesn't work, please repost with an indication of
HOW it is failing - does it not compile? or not do what you expect? If
so, what errors are you getting?

To reiterate:

Private Sub LastName_AfterUpdate
If StrComp(Me![LastName], LCase(Me![LastName]), 0) = 0 Then
Me!LastName = StrConv(Me!LastName, vbProperCase)
End If
End Sub


John W. Vinson[MVP]
 
G

Guest

Thanks, John. I have now figured out a solution.

John Vinson said:
John,

I tried your language in my database (Access 2000), tried to modify it, but
continue to get errors. The following is my current Event Procedure.

***************************
Private Sub FirstName_AfterUpdate()
Dim t_FirstName As String
t_FirstName = UCase(Left([FirstName], 1)) & Mid([FirstName], 2, 20)
Me.FirstName = t_FirstName
End Sub
Private Sub LastName_AfterUpdate()
Dim t_LastName As String
t_LastName = UCase(Left([LastName], 1)) & Mid([LastName], 2, 20)
Me.LastName = t_LastName
End Sub

Well, that bears no resemblance whatsoever to the code that I posted.
If the code I posted doesn't work, please repost with an indication of
HOW it is failing - does it not compile? or not do what you expect? If
so, what errors are you getting?

To reiterate:

Private Sub LastName_AfterUpdate
If StrComp(Me![LastName], LCase(Me![LastName]), 0) = 0 Then
Me!LastName = StrConv(Me!LastName, vbProperCase)
End If
End Sub


John W. Vinson[MVP]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top