VB to have first letter Capital Question

  • Thread starter Thread starter SITCFanTN
  • Start date Start date
S

SITCFanTN

I'm using a data input form to add records to my table. I'm collecting
address information and want the first letter of each word to be capital in
the address field. I searched this site and found some code the would
accomplish this however when I use it, I get errors. I'm wondering if it is
because the address contain numberic values, then a street name followed by
Street, Lane, Blvd. etc. Can you take a look at this and see why it is
generating an error..

Private Sub CHAPADD_AfterUpdate()
If StrComp(Me!txtCHAPADD, LCase(Me!Text), 0) = 0 Then
Me!txtCHAPADD = StrConv(Me!txtCHAPADD, vbProperCase)
End If
End Sub
 
Hi

Is there are reason why you're not just using

Private Sub CHAPADD_AfterUpdate()
Me.CHAPADD = StrConv(Me.CHAPADD, 3)
End Sub
 
I searched this site and found some code the would
accomplish this however when I use it, I get errors.

What errors? What data input triggers the error?

John W. Vinson [MVP]
 
I'm using a data input form to add records to my table. I'm collecting
address information and want the first letter of each word to be capital in
the address field. I searched this site and found some code the would
accomplish this however when I use it, I get errors. I'm wondering if it is
because the address contain numberic values, then a street name followed by
Street, Lane, Blvd. etc. Can you take a look at this and see why it is
generating an error..

Private Sub CHAPADD_AfterUpdate()
If StrComp(Me!txtCHAPADD, LCase(Me!Text), 0) = 0 Then
Me!txtCHAPADD = StrConv(Me!txtCHAPADD, vbProperCase)
End If
End Sub

If you get 'errors' it would be nice to know what errors.
This should be all you need, using VBA:

Private Sub CHAPADD_AfterUpdate()
Me!txtCHAPADD = StrConv(Me!txtCHAPADD, vbProperCase)
End Sub

Numbers and symbols are not affected.

Note: While this will capitalize the first letter of each word, some
words ought not be capitalized, i.e. van Houten, van Beethoven ,
Avenue of the Americas, etc., and it will improperly remove capitals
from words that ought to have more than one capital, i.e. O'Brien,
McDonald, Smith-Jones, etc.
 
Back
Top