| |
|
If this is your first visit, be sure to check out the FAQ by clicking the link above.
You may have to register before you can post: click the register link above to proceed.
To start viewing messages, select the forum that you want to visit from the selection below.
|
 |

11-15-10, 12:27
|
|
Registered User
|
|
Join Date: Nov 2010
Posts: 7
|
|
Help with Counting Characters
|
|
Is there anyway I can get access to count the letters in a memo field and not symbols or spaces?
Thanks
Katie
|
|

11-15-10, 12:44
|
|
Registered User
|
|
Join Date: Jun 2005
Location: Richmond, Virginia USA
Posts: 1,702
|
|
There are several ways to do this. This code, in the Click Event of a button, or in some other suitable event, will give you a count of characters without Spaces, Periods, Commas or Exclamation Points
Code:
Dim AlphaOnly As String
If Nz(Me.FieldName, "") <> "" Then
AlphaOnly = Me.FieldName
AlphaOnly = Replace(AlphaOnly, " ", "") 'Dump Spaces
AlphaOnly = Replace(AlphaOnly, ".", "") 'Dump Periods
AlphaOnly = Replace(AlphaOnly, ",", "") 'Dump Commas
AlphaOnly = Replace(AlphaOnly, "!", "") 'Dump Exclamation Points
MsgBox Len(AlphaOnly)
Else
MsgBox "Field is Empty!"
End If
You can add code in a like manner for other symbols that need to be excluded.
Linq ;0)>
__________________
Hope this helps!
The Devil's in the Details!!
All posts/responses based on Access 2000/2003
|
|

11-15-10, 12:56
|
|
Registered User
|
|
Join Date: Nov 2010
Posts: 7
|
|
|
|
Thanks, I thought there'd be a way!
|
|

11-15-10, 13:40
|
|
Registered User
|
|
Join Date: Jun 2005
Location: Richmond, Virginia USA
Posts: 1,702
|
|
Another way would be:
Code:
Dim intCounter as Integer
Dim AlphaOnlyCount As Integer
AlphaOnlyCount = 0
If Nz(Me.FieldName, "") <> "" Then
For intCounter = 1 To Len(Me.FieldName)
If Mid$(Me.FieldName, intCounter, 1) Like "[a-z]" Then
AlphaOnlyCounter = AlphaOnlyCounter + 1
End If
Next
MsgBox AlphaOnlyCounter
Else
MsgBox "Field is Empty!"
End If
__________________
Hope this helps!
The Devil's in the Details!!
All posts/responses based on Access 2000/2003
|
|

11-16-10, 06:14
|
|
Registered User
|
|
Join Date: Nov 2010
Posts: 7
|
|
Thanks, that second one looks slightly easier. I don't suppose there would be anyway to get it not to count letters between brackets? I'm trying to get counts of latin inscription lengths but the abbreviations are expanded i.e. 'h s est' becomes 'h(ic) s(itus) est'. I'm beginning to think the easiest thing to do would be to just count the letters I want by hand!
|
|

11-16-10, 06:43
|
|
King of Understatement
|
|
Join Date: Feb 2004
Location: One Flump in One Place
Posts: 14,905
|
|
It would help if you could work out ALL the rules before requesting a solution. Any new rule might invalidate all the work done so far.
Anyway, I think regex might be your best bet. If you used this function from the web (simply copy and paste) then the following works:
Code:
?len(rgxReplace(rgxReplace("This is the string (here) and more", "[^a-z]"), "\(.+\)"))
Result: 26
__________________
Testimonial:
Quote:
pootle flump
ur codings are working excelent.
|
|
|

11-16-10, 06:45
|
|
King of Understatement
|
|
Join Date: Feb 2004
Location: One Flump in One Place
Posts: 14,905
|
|
Oops - hang on - my regex expression is wrong.
__________________
Testimonial:
Quote:
pootle flump
ur codings are working excelent.
|
|
|

11-16-10, 07:03
|
|
King of Understatement
|
|
Join Date: Feb 2004
Location: One Flump in One Place
Posts: 14,905
|
|
Fixed:
Code:
?len(rgxReplace(rgxReplace("This is the string (here) and more (another bracket)", "\([^\(\)]+\)", , , True), "[^a-z]", , , True))
returns 22.
__________________
Testimonial:
Quote:
pootle flump
ur codings are working excelent.
|
|
|

11-16-10, 07:48
|
|
Registered User
|
|
Join Date: Nov 2010
Posts: 7
|
|
Yeah, sorry about that. I thought I had...then realised I'd forgotten to take account of the expansions. Thanks for the help.
|
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|