Number of letters in a field (1 Viewer)

diakis

Registered User.
Local time
Tomorrow, 01:34
Joined
Jul 4, 2006
Messages
16
I have a field with 3 records: 1=Henning, 2=Daniel and 3=Santiago. I want to do a field in a query to give me the number of letters in each one record but the same letter to sum once. The field in the query must give: 1=5, 2=6 and 3=7.
Thanks
 

Trevor G

Registered User.
Local time
Today, 23:34
Joined
Oct 1, 2009
Messages
2,341
You can't do this with Functions in Access, you would need VBA to do this.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 06:34
Joined
May 7, 2009
Messages
19,229
put this in any Module:
Code:
Public Function CountDistinctLetter(ByVal strSource As Variant) As Integer

    Dim strTemp As String
    Dim intLen As Integer
    Dim intLoop As Integer
    Dim strChar As String
    
    strSource = strSource & ""
    intLen = Len(strSource)
    
    For intLoop = 1 To intLen
        strChar = Mid(strSource, intLoop, 1)
        ' only letter and digit
        ' remove this IF if you also want to test for these characters
        If InStr(1, " .,;!@#$%^&*()_-:|\'<>?/\=0123456789" & """", strChar) = 0 Then
            If InStr(1, strTemp, strChar) = 0 Then
            'If InStr(1, stretmp, strChar, vbTextCompare) = 0 Then
                strTemp = strTemp & strChar
            End If
        End If
    Next intLoop
    CountDistinctLetter = Len(strTemp)
End Function
In your query:

TextCount: Val([yourField] & "") & "=" & CountDistinctLetter([yourField])
 

diakis

Registered User.
Local time
Tomorrow, 01:34
Joined
Jul 4, 2006
Messages
16
Thanks again. It works very well
 

Users who are viewing this thread

Top Bottom