VB to have first letter Capital Question

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
 
W

Wayne-I-M

Hi

Is there are reason why you're not just using

Private Sub CHAPADD_AfterUpdate()
Me.CHAPADD = StrConv(Me.CHAPADD, 3)
End Sub
 
J

John W. Vinson

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]
 
F

fredg

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.
 

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