Results 1 to 9 of 9
  1. #1
    Misha is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Feb 2012
    Posts
    8

    Count uppercase letters

    Hello everybody,



    I have field in one form with number of letters in upper and lower case with spaces. I need to count number of upper case letters only and put the number in different field. I found following code:

    Me.Text47 = Len([Work Order])


    "Work Order" - field with letters to be count
    "Text47" - field, where result must put.

    But this code counts all letters with spaces. Can you please help to change this code.

    Thanks

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Try this UDF in a module:
    Code:
    Option Compare Binary
    Option Explicit
    
    Public Function CountUpper(strIn As String) As Long
    '-- Count all of the UpperCase letters in strIn
       Dim offset As Long
       For offset = 1 To Len(strIn)
          CountUpper = CountUpper + IsUpper(Mid(strIn, offset, 1))
       Next offset
    End Function
    
    Public Function IsUpper(strIn As String) As Integer
       Select Case strIn
          Case "A" To "Z"
             IsUpper = 1
          Case Else
             IsUpper = 0
       End Select
    End Function

  3. #3
    Misha is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Feb 2012
    Posts
    8
    Thanks a lot, it helped.

  4. #4
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Glad we could help.

  5. #5
    Misha is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Feb 2012
    Posts
    8
    Sorry for late reply, but I just figured out that when field with letters is empty, so instead to get "0" in second field or have just empty field I get error.Click image for larger version. 

Name:	Count letters error.jpg 
Views:	5 
Size:	18.2 KB 
ID:	6498

  6. #6
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    try:
    Code:
    Option Compare Binary
    Option Explicit
    Public Function CountUpper(strIn As String) As Long
    '-- Count all of the UpperCase letters in strIn
       Dim offset As Long
       If Len(strIn & "") > 0 Then
          For offset = 1 To Len(strIn)
             CountUpper = CountUpper + IsUpper(Mid(strIn, offset, 1))
          Next offset
       Else
          CountUpper = 0
       End If
    End Function
    
    Public Function IsUpper(strIn As String) As Integer
       Select Case strIn
          Case "A" To "Z"
             IsUpper = 1
          Case Else
             IsUpper = 0
       End Select
    End Function

  7. #7
    Misha is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Feb 2012
    Posts
    8
    Now I get same error if the field is empty and another error if there any characters - Click image for larger version. 

Name:	Count letters error 2.jpg 
Views:	2 
Size:	27.3 KB 
ID:	6501
    Attached Thumbnails Attached Thumbnails Count letters error 2.jpg  

  8. #8
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Post the entire module between #code tags# in advanced.

  9. #9
    Misha is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Feb 2012
    Posts
    8
    Thank you for your help, this is the code I used with module you provided:

    length = Len([Work Order])

    If length > 0 Then Text204 = CountUpper([Work Order]) Else Text204 = ""


    Now it works with letters and when the field is empty.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. uppercase?
    By slimjen in forum Forms
    Replies: 2
    Last Post: 01-31-2012, 03:30 PM
  2. Query for Partial Uppercase Text in Field
    By pjordan@drcog.org in forum Queries
    Replies: 15
    Last Post: 12-29-2011, 12:53 PM
  3. Replies: 1
    Last Post: 03-01-2011, 03:01 PM
  4. Changing table names from lowercase to uppercase
    By supernix in forum Database Design
    Replies: 1
    Last Post: 09-03-2010, 10:08 PM
  5. Uppercase to Lowercase
    By tigers in forum Reports
    Replies: 1
    Last Post: 09-28-2009, 10:48 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums