vbProperCase

S

Sue

I'm using the subject command in my address field to ensure the first letter of each word is uppercase per the exampl

PrspDemoAddress = StrConv(PrspDemoAddress, vbProperCase

My problem is if someone types PO Box it's defaults to Po Box or NE it defaults to Ne

How can I change the above so it doesn't affect subsequent letter after the first but ensure the first letter of each word is a capital letter

Thanks in advance
 
F

fredg

I'm using the subject command in my address field to ensure the first letter of each word is uppercase per the example

PrspDemoAddress = StrConv(PrspDemoAddress, vbProperCase)

My problem is if someone types PO Box it's defaults to Po Box or NE it defaults to Ne.

How can I change the above so it doesn't affect subsequent letter after the first but ensure the first letter of each word is a capital letter.

Thanks in advance.

You can't.
1) StrConv()can be used to set ALL characters to lower case (same as
LCase()), ALL characters to upper case (same a UCase()), or just the
FIRST character of every word to Upper case and all the other letters
in the word to lower case (as you have posted).

There are many words which are affected besides PO Box, and state name
abbreviations. Think of IBM, ABC, CBS, HBO, McDonalds, O'Hare, van den
Steen, Bourne-White, etc. none of which are properly capitalized if
you use StrConv().

You can use StrConv() along with a table of exceptions, and have your
code use a DLookUp() to see if that word is in the table and ask if
the exception should be used or the StrConv().

2) If you are typing addresses, the State should be in it's own table
of States and the Field on the form should be a combo box with the
state abbreviation already in capitals, i.e. NE NY CA etc. in which
case StrConv() is not needed for that field.

The State field can then easily be added to the address for printing,
using an unbound control:
=[City] & ", " & State & " " & [ZipCodeField]
 
S

Sue

Thanks for the information. How do you setup something like that. I don't know how to setup an exception table

Thanks in advance
 
F

fredg

Thanks for the information. How do you setup something like that. I don't know how to setup an exception table.

Thanks in advance

Sue.

Paste the following code into a Module.
Function ConvExceptionsInField(StrIn As String) As String

' Will find exceptions to Proper Case capitalization of names.
' In a multi-word string
On Error Resume Next

Dim strWord As String
Dim intX As Integer
Dim intY As Integer
Dim strNewString As String
Dim intResponse As Integer
Dim strFind As String

StrIn = StrIn & " "

intX = InStr(1, StrIn, " ")
strWord = StrConv(Mid(StrIn, intY + 1, intX - 1), vbProperCase)

Do While intX <> 0

If DCount("*", "tblExceptions", "[ExceptName]= " & Chr(34) & strWord &
Chr(34) & "") > 0 Then

strFind = DLookup("[ExceptName]", "tblExceptions", "[ExceptName] =
" & Chr(34) & strWord & Chr(34) & "")

intResponse = MsgBox(strFind & vbCrLf & " is an exception name." &
vbCrLf _
& " Accept the above capitalization? Y/N ?", vbYesNo, "Exception
found!")

If intResponse = vbYes Then
strWord = strFind
End If
End If
strNewString = strNewString & strWord & " "
intY = intX + 1
intX = InStr(intY, StrIn, " ")
strWord = StrConv(Mid(StrIn, intY, intX - intY), vbProperCase)
Loop

ConvExceptionsInField = strNewString

End Function

======

In the AfterUpdate event of the control on your form:

If Not IsNull([ControlName]) Then
[ControlName] = ConvExceptionsInField([ControlName])
End If
========
Then create a new table.
Table Name: tblExceptions
Field names: [ID] AutoNumber Indexed No Duplicates Prime Key field
[ExceptName] Text

Save the table, then enter each word exactly as you wish to have it.
van, PO, McDaniel, McDaniels, IBM, ABC, etc. in a record.
Note: it is the one word (van) that is saved by itself in the field,
not the complete name (van Gough), and PO (not PO Box), etc.
Update the table as new exceptions are found.

As the user enters the data in the form and goes to the next field,
the AfterUpdate event will fire and you will get a message if a word
in the field is in the table. Click Yes to accept the new
capitalization, or No to keep the entry as entered in the control.

Please keep in mind that with peoples names, there may be more than
one correct way to capitalize, O'Connor and O'connor are both correct.
I hope this helps.
 
S

Sue

That's looks great. Can't wait to try that. I'm so excited. Hope they let me get to it today though.
 
S

Sue

I've tried your code and I get the following highlighed in red in the module

If DCount("*", "tblExceptions", "[ExceptName]= " & Chr(34) & strWord
Chr(34) & "") > 0 The

strFind = DLookup("[ExceptName]", "tblExceptions", "[ExceptName]
" & Chr(34) & strWord & Chr(34) & ""

intResponse = MsgBox(strFind & vbCrLf & " is an exception name."
vbCrLf
& " Accept the above capitalization? Y/N ?", vbYesNo, "Exceptio

I'm not sure what to look for here

Also in the afterupdate of the control on the form how would I reference thi

If Not IsNull([ControlName]) Then ------------Do I enter the control name on the form i.e. PrspDemoLastNam
[ControlName] = ConvExceptionsInField([ControlName])-----------On the first control on this line would it be PrspDemoLastname----------On the second control would it be PrspDemoLastNam
End I

Do I have to save the module by a certain name

Thanks so much for your help
 
F

fredg

On Tue, 8 Jun 2004 07:16:07 -0700, Sue wrote:

See comments interspersed below....
I've tried your code and I get the following highlighed in red in the module.

If DCount("*", "tblExceptions", "[ExceptName]= " & Chr(34) & strWord &
Chr(34) & "") > 0 Then

The line If DCount("*" etc ...)>0 Then should all be on one line.
strFind = DLookup("[ExceptName]", "tblExceptions", "[ExceptName] =
" & Chr(34) & strWord & Chr(34) & "")

The line strFind = DLookup( etc .... & strWord & chr(34) & "'")
should all be on one line.
intResponse = MsgBox(strFind & vbCrLf & " is an exception name." &
vbCrLf _


The line intResponse = etc ......& vbCrLf _ should all be on one
line
& " Accept the above capitalization? Y/N ?", vbYesNo, "Exception
You are missing some additional text here!

It should read & "Accept etc ... vbYesNo, "Exception found!") on one
line.
Perhaps missing just in copying to this post, or perhaps not entered
in the module.
I'm not sure what to look for here.

Also in the afterupdate of the control on the form how would I reference this

If Not IsNull([ControlName]) Then ------------Do I enter the control name on the form i.e. PrspDemoLastName
[ControlName] = ConvExceptionsInField([ControlName])-----------On the first control on this line would it be PrspDemoLastname----------On the second control would it be PrspDemoLastName
End If

I can only use generic names as I have no idea of your actual field
names. Yes, use your field and table names to replace my generic ones.
In the AfterUpdate event of the [PrspDemoLastName] field
If Not IsNull([PrspDemoLastName]) Then
[PrspDemoLastName] = ConvExceptionsInField([PrspDemoLastName])
End If

Make sure you do not copy the leading >'s place by the email reader.
There are only two usages of the > symbol.
1) Do While intX <> 0
2) & strWord & Chr(34) & "") > 0 Then

any others a placed by the email reader and should not be copied.
Do I have to save the module by a certain name ?

Not by a certain name, but NOT by the same name as the function name.
In other words NOT ConvExceptionsInfield. I would use
mdlTextExceptions or something meaningful to you (not already used by
a different module).
Thanks so much for your help.

Just a reminder mentioned in my previous post.
If this is used for addresses, you are making a database design error
by entering city, state, and zip in one field.
They should each have their own field, as should the prospects
LastName, FirstName, and Street address.

It is much simpler to concatenate (put together) an address from
several different fields, then to try, at some time in the (very near)
future, to separate them out.

If you decide to use individual fields, I have a bit simpler code to
find exceptions for names in a field (van den Steen), as opposed to
individual words in a field (van, then den, then Steen).
You won't be able to use it in a Street address field (as each address
is different).
If you want that post back.
 
S

Sue

I get an Invalid outside procedures. Comments noted with ----------

Option Compare Databas

' Will find exceptions to Proper Case capitalization of names
' In a multi-word strin
On Error Resume Next -----------------Errors out on here with invalid outside procedure when you open up the for

Dim strWord As Strin
Dim intX As Intege
Dim intY As Intege
Dim strNewString As Strin
Dim intResponse As Intege
Dim strFind As Strin

StrIn = StrIn & "

intX = InStr(1, StrIn, " "
strWord = StrConv(Mid(StrIn, intY + 1, intX - 1), vbProperCase

Do While intX <>

If DCount("*", "tblExceptions", "[ExceptName]= " & Chr(34) & strWord & Chr(34) & "") > 0 The

strFind = DLookup("[ExceptName]", "tblExceptions", "[ExceptName] = " & Chr(34) & strWord & Chr(34) & ""

intResponse = MsgBox(strFind & vbCrLf & " is an exception name." & vbCrLf & " Accept the above capitalization? Y/N ?", vbYesNo, "Exception found! ") ------------------- I removed " from the end here. It kept highlighted in red. Was that correct to do

If intResponse = vbYes The
strWord = strFin
End I
End I
strNewString = strNewString & strWord & "
intY = intX +
intX = InStr(intY, StrIn, " "
strWord = StrConv(Mid(StrIn, intY, intX - intY), vbProperCase
Loo

ConvExceptionsInField = strNewStrin

End Functio

I'm going to be using this for names as well as addresses. You mentioned something about you had a different one for names. Can you please let me know what it is. Much appreciated. Sorry to be a pain
 
F

fredg

I'll try your suggestions soon. Time seems to be escaping me lately.

I do have the city, state and zip code separated.

I'm planning to use this for the last name, first name, middle name, nick name, address line 1, address line 2 and city field.

Should I not be doing it this way?

No you should not be doing it this way.

You should have a LastName field, a FirstName field, an Initial field,
a NickName field, an Address1 field, an Address2 field.
You already do have separate City, State and Zip fields, so that's
good.
Also important is a RecordID field, indexed with no duplicates.

It's easy to assemble a mailing label or a list from the above, and
sort it if wanted by City, or Zip code, or LastName, etc. It's very
difficult to do all of that if the Prospects name field is something
like:
John M. Smith Jack 123 So. Main Street, PO Box 258 Cincinnati

Some records will not have a middle initial, some will not have a
nickname, some will not have two addresses.
Is the above's last name Jack or is that his nickname?
You have confusion and lots of work to make sense out of all of this.
Access is designed for atomic data in a field (the smallest that is
useful).

How would you sort the above by City?, Or by Last Name? Or find John
Smith's records?
To assemble a mailing list for the properly separated fields, you
would use something like this in an address label.

Using 3 unbound controls:

=[FirstName] & " " + ([Initial] & " ") & [LastName]
Use of the + above will remove the empty initial spaces if there is no
initial.

= IIf IsNull([Address1]),[Address2],[Address1])
If Address1 is blank, Address2 will print

= [City] & ", " & [State] & " " & [ZipCode]

I would strongly suggest you search these news groups for posts on
parsing fields, splitting fields, separating last names from first
names in a field, etc. There are lots of questions by posters who
finally realize they have improperly designed databases. For some of
them it's a struggle to make it right afterwards.

Good luck.
 
S

Sue

Hi Fred.

Sorry but maybe I wasn't clear. I have the following fields separated.

Last name (PrspDemoLastName)
First name (PrspDemoFirstName)
Middle name (PrspDemoMiddleName)
Nick Name (PrspDemoNickName)
AddressLine1 (PrspDemoAddrLine1)
AddressLine2 (PrspDemoAddrLine2)
City (PrspDemoCity)
State (PrspDemoState)
Zip (PrspDemoZip)

All are separate fields by themselfs on the form. I was looking at using the code you provided me on AddressLine1 and AddressLine2.

I was also planning on adding to the Last name, first name, middle name, nick name. However you mentioned a better way to do this so those plans have changed and I'll be using the new code that you mentioned for these particular fields to ensure proper capitalization of names etc.

On the address line code I've implemented the code you provided me. When I open the form however it goes straight into the vb code referencing invalid outside procedures. I've included the code you provided me with comments noted with ------------ where the errors have occurred. I've tried removing the On Error Resume Next. When I do that however the next invalid outside procedure occurs here StrIn = StrIn & " "


Option Compare Database

' Will find exceptions to Proper Case capitalization of names.
' In a multi-word string
On Error Resume Next -----------------Errors out on here with invalid outside procedure when you open up the form

Dim strWord As String
Dim intX As Integer
Dim intY As Integer
Dim strNewString As String
Dim intResponse As Integer
Dim strFind As String

StrIn = StrIn & " "

intX = InStr(1, StrIn, " ")
strWord = StrConv(Mid(StrIn, intY + 1, intX - 1), vbProperCase)

Do While intX <> 0

If DCount("*", "tblExceptions", "[ExceptName]= " & Chr(34) & strWord & Chr(34) & "") > 0 Then

strFind = DLookup("[ExceptName]", "tblExceptions", "[ExceptName] = " & Chr(34) & strWord & Chr(34) & "")

intResponse = MsgBox(strFind & vbCrLf & " is an exception name." & vbCrLf & " Accept the above capitalization? Y/N ?", vbYesNo, "Exception found! ") ------------------- I removed " from the end here. It kept highlighted in red. Was that correct to do?

If intResponse = vbYes Then
strWord = strFind
End If
End If
strNewString = strNewString & strWord & " "
intY = intX + 1
intX = InStr(intY, StrIn, " ")
strWord = StrConv(Mid(StrIn, intY, intX - intY), vbProperCase)
Loop

ConvExceptionsInField = strNewString

End Function
 
S

Sue

Hi Fred

I have the following fields setup

LastName (PrspDemoLastName)
FirstName (PrspDemoFirstName)
MiddleName (PrspDemoMiddleName)
NickName (PrspDemoNickName)
AddressLine1 (PrspDemoAddrLine1)
AddressLine2 (PrspDemoAddrLine2)
City (PrspDemoCity)
State (PrspDemoState)
ZipCode (PrspDemoZipCode)

I plan on using the code you provded me in the AddressLine1 and AddressLine2. I've implemented the code but when I open the form I receive an outside invalidation procedure error.

Option Compare Database

' Will find exceptions to Proper Case capitalization of names.
' In a multi-word string
On Error Resume Next -----------------Errors out on here with invalid outside procedure when you open up the form. If I comment this out I receive the same error on StrIn

Dim strWord As String
Dim intX As Integer
Dim intY As Integer
Dim strNewString As String
Dim intResponse As Integer
Dim strFind As String

StrIn = StrIn & " " ------------------- Next invalid procedure appears here if On Error Resume Next is commented out.

intX = InStr(1, StrIn, " ")
strWord = StrConv(Mid(StrIn, intY + 1, intX - 1), vbProperCase)

Do While intX <> 0

If DCount("*", "tblExceptions", "[ExceptName]= " & Chr(34) & strWord & Chr(34) & "") > 0 Then

strFind = DLookup("[ExceptName]", "tblExceptions", "[ExceptName] = " & Chr(34) & strWord & Chr(34) & "")

intResponse = MsgBox(strFind & vbCrLf & " is an exception name." & vbCrLf & " Accept the above capitalization? Y/N ?", vbYesNo, "Exception found! ") ------------------- I removed " from the end here. It kept highlighted in red. Was that correct to do?

If intResponse = vbYes Then
strWord = strFind
End If
End If
strNewString = strNewString & strWord & " "
intY = intX + 1
intX = InStr(intY, StrIn, " ")
strWord = StrConv(Mid(StrIn, intY, intX - intY), vbProperCase)
Loop

ConvExceptionsInField = strNewString

End Function

Other then the above I have been able to test the rest. I look forward to receiving the code from you for the name fields.

Thanks in advance.



fredg said:
I'll try your suggestions soon. Time seems to be escaping me lately.

I do have the city, state and zip code separated.

I'm planning to use this for the last name, first name, middle name, nick name, address line 1, address line 2 and city field.

Should I not be doing it this way?

No you should not be doing it this way.

You should have a LastName field, a FirstName field, an Initial field,
a NickName field, an Address1 field, an Address2 field.
You already do have separate City, State and Zip fields, so that's
good.
Also important is a RecordID field, indexed with no duplicates.

It's easy to assemble a mailing label or a list from the above, and
sort it if wanted by City, or Zip code, or LastName, etc. It's very
difficult to do all of that if the Prospects name field is something
like:
John M. Smith Jack 123 So. Main Street, PO Box 258 Cincinnati

Some records will not have a middle initial, some will not have a
nickname, some will not have two addresses.
Is the above's last name Jack or is that his nickname?
You have confusion and lots of work to make sense out of all of this.
Access is designed for atomic data in a field (the smallest that is
useful).

How would you sort the above by City?, Or by Last Name? Or find John
Smith's records?
To assemble a mailing list for the properly separated fields, you
would use something like this in an address label.

Using 3 unbound controls:

=[FirstName] & " " + ([Initial] & " ") & [LastName]
Use of the + above will remove the empty initial spaces if there is no
initial.

= IIf IsNull([Address1]),[Address2],[Address1])
If Address1 is blank, Address2 will print

= [City] & ", " & [State] & " " & [ZipCode]

I would strongly suggest you search these news groups for posts on
parsing fields, splitting fields, separating last names from first
names in a field, etc. There are lots of questions by posters who
finally realize they have improperly designed databases. For some of
them it's a struggle to make it right afterwards.

Good luck.
 
F

fredg

On Tue, 8 Jun 2004 20:30:01 -0700, Sue wrote:

Sue,
This is the third post you've sent regarding this. As this is the
latest one, I'll assume this supersedes all the others.
My comments are interspersed below.

Hi Fred

I have the following fields setup

LastName (PrspDemoLastName)
FirstName (PrspDemoFirstName)
MiddleName (PrspDemoMiddleName)
NickName (PrspDemoNickName)
AddressLine1 (PrspDemoAddrLine1)
AddressLine2 (PrspDemoAddrLine2)
City (PrspDemoCity)
State (PrspDemoState)
ZipCode (PrspDemoZipCode)

Now you got it right. :)
I plan on using the code you provded me in the AddressLine1 and AddressLine2. I've implemented the code but when I open the form I receive an outside invalidation procedure error.

I'm attaching different code here which will compare the entire field
for capitalization, not just each word in the field.

In the [PrspDemoLastName] After Update event:

If Not IsNull([PrspDemoLastName]) Then
[PrspDemoLastName] = ConvExceptions([LastName])
End If
=======
Place the following new function in a module.
Remember to save the module under a different name,
**You can delete the previous one that you're having some problems
with if you want**


If you have a problem with error's when you write this code, please
COPY and PASTE the code from the code window directly onto a reply
mail so I can see how it actually appears, not how it appears when you
re-type it.

Regarding the error with the

vbYesNo, "Exception found! ") ------------------- I removed " from
the end here. It kept highlighted in red. Was that correct to do?

When using quotation marks they are always in pairs. If VBA won't
accept one at the end of a line, look to see where it's missing
partner should be. That particular line has 3 sets of quotes (6
total). It may be because the line has been incorrectly split when it
was copied and all that needs doing is making it into one line instead
of two.

I have indicate line breaks in the code with a '***
so the code line BELOW the '*** is all on one line, no matter how many
lines your email reader shows it on.
After you copy the code remove each of the ' ***'s .

I've added an Option Explicit statement to the declarations section
which should help you find compile errors before you run the code.

Option Compare Database
Option Explicit
===
Function ConvExceptions(StrIn As String) As String

' Will find exceptions to Proper Case capitalization of names.
' Checks for the complete name in a field.
' van der Hoff, van Beethoven, McDaniel

' ***
If DCount("*", "tblExceptions", "[ExceptName] = " & Chr(34) & StrIn &
Chr(34) & "") > 0 Then
' ***
Dim intResponse As Integer
' ***
Dim strFind As String
' ***
strFind = DLookup("[ExceptName]", "tblExceptions", "[ExceptName] =
" & Chr(34) & StrIn & Chr(34) & "")
' ***
intResponse = MsgBox(strFind & vbCrLf & " is an exception name." &
vbCrLf & "Accept the above capitalization? Y/N ?", vbYesNo,
"Exception found!")
' ***
If intResponse = vbYes Then
' ***
ConvExceptions = strFind
' ***
Exit Function
' ***
End If
' ***
End If
' ***
ConvExceptions = StrConv(StrIn, 3)
' ***
End Function
=================
You can use the same tblExceptions from the previous messages, but
you must store the exact name in each record, i.e. van Beethoven,
McDonald, O'Brien, van den Steen, etc.

If you wish to use this for First Name entry and City entry also, use
the same code as the Last Name AfterUpdate event, but place it in that
Control's (FirstName or City) AfterUpdate event, changing the field
name in the code, of course.

You can use names, cities, states, nickname in the table if you want,
but just one per record.
It will NOT find words in the Street Address field because address
data such as PO Box 123 is not the same as PO Box 456.

For the Address field, if you have Access 2000 or newer, you can check
for PO Box capitalization in the address field directly without using
the table of exceptions.

In the Address AfterUpdate event:

[Address] = StrConv([Address],vbProperCase)
If InStr([Address],"Po Box ") > 0 Then
[Address] = Replace([Address],"Po Box ","PO Box ")
End If

I hope we haven't covered too much ground.
Good luck.
Fred

=======================
Scratch this previous code beneath this line...
Option Compare Database

' Will find exceptions to Proper Case capitalization of names.
' In a multi-word string
On Error Resume Next -----------------Errors out on here with invalid outside procedure when you open up the form. If I comment this out I receive the same error on StrIn

Dim strWord As String
Dim intX As Integer
Dim intY As Integer
Dim strNewString As String
Dim intResponse As Integer
Dim strFind As String

StrIn = StrIn & " " ------------------- Next invalid procedure appears here if On Error Resume Next is commented out.

intX = InStr(1, StrIn, " ")
strWord = StrConv(Mid(StrIn, intY + 1, intX - 1), vbProperCase)

Do While intX <> 0

If DCount("*", "tblExceptions", "[ExceptName]= " & Chr(34) & strWord & Chr(34) & "") > 0 Then

strFind = DLookup("[ExceptName]", "tblExceptions", "[ExceptName] = " & Chr(34) & strWord & Chr(34) & "")

intResponse = MsgBox(strFind & vbCrLf & " is an exception name." & vbCrLf & " Accept the above capitalization? Y/N ?", vbYesNo, "Exception found! ") ------------------- I removed " from the end here. It kept highlighted in red. Was that correct to do?

If intResponse = vbYes Then
strWord = strFind
End If
End If
strNewString = strNewString & strWord & " "
intY = intX + 1
intX = InStr(intY, StrIn, " ")
strWord = StrConv(Mid(StrIn, intY, intX - intY), vbProperCase)
Loop

ConvExceptionsInField = strNewString

End Function

Other then the above I have been able to test the rest. I look forward to receiving the code from you for the name fields.

Thanks in advance.

fredg said:
I'll try your suggestions soon. Time seems to be escaping me lately.

I do have the city, state and zip code separated.

I'm planning to use this for the last name, first name, middle name, nick name, address line 1, address line 2 and city field.

Should I not be doing it this way?

No you should not be doing it this way.

You should have a LastName field, a FirstName field, an Initial field,
a NickName field, an Address1 field, an Address2 field.
You already do have separate City, State and Zip fields, so that's
good.
Also important is a RecordID field, indexed with no duplicates.

It's easy to assemble a mailing label or a list from the above, and
sort it if wanted by City, or Zip code, or LastName, etc. It's very
difficult to do all of that if the Prospects name field is something
like:
John M. Smith Jack 123 So. Main Street, PO Box 258 Cincinnati

Some records will not have a middle initial, some will not have a
nickname, some will not have two addresses.
Is the above's last name Jack or is that his nickname?
You have confusion and lots of work to make sense out of all of this.
Access is designed for atomic data in a field (the smallest that is
useful).

How would you sort the above by City?, Or by Last Name? Or find John
Smith's records?
To assemble a mailing list for the properly separated fields, you
would use something like this in an address label.

Using 3 unbound controls:

=[FirstName] & " " + ([Initial] & " ") & [LastName]
Use of the + above will remove the empty initial spaces if there is no
initial.

= IIf IsNull([Address1]),[Address2],[Address1])
If Address1 is blank, Address2 will print

= [City] & ", " & [State] & " " & [ZipCode]

I would strongly suggest you search these news groups for posts on
parsing fields, splitting fields, separating last names from first
names in a field, etc. There are lots of questions by posters who
finally realize they have improperly designed databases. For some of
them it's a struggle to make it right afterwards.

Good luck.
 

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