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.

 
Go Back  dBforums > PC based Database Applications > Microsoft Access > Help with Counting Characters

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-15-10, 12:27
katie_walsh katie_walsh is offline
Registered User
 
Join Date: Nov 2010
Posts: 7
Question 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
Reply With Quote
  #2 (permalink)  
Old 11-15-10, 12:44
Missinglinq Missinglinq is offline
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
Reply With Quote
  #3 (permalink)  
Old 11-15-10, 12:56
katie_walsh katie_walsh is offline
Registered User
 
Join Date: Nov 2010
Posts: 7
Thanks, I thought there'd be a way!
Reply With Quote
  #4 (permalink)  
Old 11-15-10, 13:40
Missinglinq Missinglinq is offline
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
Reply With Quote
  #5 (permalink)  
Old 11-16-10, 06:14
katie_walsh katie_walsh is offline
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!
Reply With Quote
  #6 (permalink)  
Old 11-16-10, 06:43
pootle flump pootle flump is offline
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.
Reply With Quote
  #7 (permalink)  
Old 11-16-10, 06:45
pootle flump pootle flump is offline
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.
Reply With Quote
  #8 (permalink)  
Old 11-16-10, 07:03
pootle flump pootle flump is offline
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.
Reply With Quote
  #9 (permalink)  
Old 11-16-10, 07:48
katie_walsh katie_walsh is offline
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.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On