Pinecone
02-19-2000, 04:13 PM
How do I set a field so that the first letter always defaults to a capital (ie name) so that I don't have to use the shift key when entering data. I found how to default the whole field to caps but ???
Thanks in advance.
Nancy
Travis
02-19-2000, 10:25 PM
Add this code to the On Change Event of the control
Private Sub Field1_Change()
me.[Field1]=strconv(me.[Field1],vbProperCase)
End Sub
Pinecone
02-20-2000, 06:12 AM
I put the code in and made sure the name field was Field1 (because I don't know this aspect of Access) I got it to work once and then it wouldn't let me type anything in the field or delete the contents.
This is in the Class Module:
Option Compare Database
Option Explicit
Private Sub Field1_Change()
Me.[Field1] = StrConv(Me.[Field1],vbProperCase)
End Sub
???
R. Hicks
02-20-2000, 06:42 AM
Put Travis's code in the After Update event of your Text Box and remove it from the On Change event. The code will convert the entry to proper case after you make a change and leave that text box. I tried the On Change event, and it done the same thing that you said.
HTH
RDH
[This message has been edited by R. Hicks (edited 02-20-2000).]
Pinecone
02-20-2000, 01:40 PM
Works perfectly! Thank you so much.
Nancy
Pinecone
02-25-2000, 06:52 AM
It is great to not have to type in caps but I found one gliche in my address line. I type in RR addresses alot and it changes them to Rr. Is there a string operation that can change any occurance in the line of "Rr " to "RR "
Thanks in advance
Nancy
Here's a function that I designed to work with addresses. It watches for things like RR or directional indicators like NE, NW, etc. It's not the most elegant code in the world, but it has worked quite well in a database where they enter dozens of addresses every day. Put the function in a module, then in the AfterUpdate property of the address field put Me!Address = SetProper(Address).
==================================
Function SetProper(ByVal strFixCase As String) As String
On Error GoTo Err_SetProper
Dim I As Integer, intSkip As Integer, intASC As Integer, intLen As Integer
Dim intPos1 As Integer, intPos2 As Integer, intPos3 As Integer
Dim intPos4 As Integer, intPos5 As Integer, intPos6 As Integer
Dim intPos7 As Integer, intPos8 As Integer, intPos9 As Integer
Dim strUpper As String, strLast As String, strDir As String
strUpper = strFixCase
strLast = " "
strUpper = LCase$(strUpper)
intLen = Len(strUpper)
For I = 1 To intLen
If intSkip > 0 Then
intSkip = intSkip - 1
GoTo NextOne
End If
If strLast = " " Then
If Len(strUpper) - I > 2 Then
If Mid$(strUpper, I, 2) = "o'" Or Mid$(strUpper, I, 2) = "mc" Then
Mid$(strUpper, I, 1) = UCase$(Mid$(strUpper, I, 1))
intSkip = 1
GoTo NextOne
End If
If Mid$(strUpper, I, 3) = "mac" Then
Mid$(strUpper, I, 1) = UCase$(Mid$(strUpper, I, 1))
intSkip = 2
GoTo NextOne
End If
End If
If Mid$(strUpper, I, 3) = "po " Or Mid$(strUpper, I, 3) = "ne " Or Mid$(strUpper, I, 3) = "se " Or Mid$(strUpper, I, 3) = "sw " Then
Mid$(strUpper, I, 3) = UCase$(Mid$(strUpper, I, 3))
intSkip = 1
GoTo NextOne
End If
If Mid$(strUpper, I, 2) = "nw" Or Mid$(strUpper, I, 2) = "rr" Then
Mid$(strUpper, I, 2) = UCase$(Mid$(strUpper, I, 2))
intSkip = 1
GoTo NextOne
End If
End If
intASC = Asc(strLast)
If intASC = 39 Or (intASC >= 97 And intASC <= 122) Or (intASC >= 65 And intASC <= 90) Or (intASC >= 224 And intASC <= 246) Or (intASC >= 248) Then
Else
Mid$(strUpper, I, 1) = UCase$(Mid$(strUpper, I, 1))
End If
strLast = Mid$(strUpper, I, 1)
NextOne:
Next I
SetProper = strUpper
intPos1 = InStr(SetProper, "1st")
intPos2 = InStr(SetProper, "2nd")
intPos3 = InStr(SetProper, "3rd")
intPos4 = InStr(SetProper, "4th")
intPos5 = InStr(SetProper, "5th")
intPos6 = InStr(SetProper, "6th")
intPos7 = InStr(SetProper, "7th")
intPos8 = InStr(SetProper, "8th")
intPos9 = InStr(SetProper, "9th")
If intPos1 > 0 Then
SetProper = Left$(SetProper, intPos1 - 1) & "1st" & Mid$(SetProper, intPos1 + 3)
End If
If intPos2 > 0 Then
SetProper = Left$(SetProper, intPos2 - 1) & "2nd" & Mid$(SetProper, intPos2 + 3)
End If
If intPos3 > 0 Then
SetProper = Left$(SetProper, intPos3 - 1) & "3rd" & Mid$(SetProper, intPos3 + 3)
End If
If intPos4 > 0 Then
SetProper = Left$(SetProper, intPos4 - 1) & "4th" & Mid$(SetProper, intPos4 + 3)
End If
If intPos5 > 0 Then
SetProper = Left$(SetProper, intPos5 - 1) & "5th" & Mid$(SetProper, intPos5 + 3)
End If
If intPos6 > 0 Then
SetProper = Left$(SetProper, intPos6 - 1) & "6th" & Mid$(SetProper, intPos6 + 3)
End If
If intPos7 > 0 Then
SetProper = Left$(SetProper, intPos7 - 1) & "7th" & Mid$(SetProper, intPos7 + 3)
End If
If intPos8 > 0 Then
SetProper = Left$(SetProper, intPos8 - 1) & "8th" & Mid$(SetProper, intPos8 + 3)
End If
If intPos9 > 0 Then
SetProper = Left$(SetProper, intPos9 - 1) & "9th" & Mid$(SetProper, intPos9 + 3)
End If
strDir = Right(SetProper, 3)
If strDir = " NE" Then
SetProper = Left$(SetProper, intLen - 3) & " NE"
End If
If strDir = " SE" Then
SetProper = Left$(SetProper, intLen - 3) & " SE"
End If
Exit_SetProper:
Exit Function
Err_SetProper:
MsgBox "Error: " + Error$
Resume Exit_SetProper
End Function
GerryL
02-27-2000, 11:20 PM
Hi:
I'm not sure if there is a format symbol to use to do this but I would rather suggest a workaround.
In the AfterUpdate event of your textbox, you can put the formatting code like this:
txtName = UCase(Left(txtName, 1)) & LCase(Mid(txtName, 2))
Pinecone
02-28-2000, 12:59 PM
Thanks for your help. I am trying to use Axis' solution. I think I got the module set up okay. (I haven't used one in ACCESS before) I have the impression there is a problem in the calling of the module:
Me!Address = SetProper(Address)
I get the error message: "expected variable or procedure, not module." I haven't got the proper documentation to look this up. Is the call okay?
Email me directly at axis@lunatrix.com, and I'll help you figure out what's wrong.