Results 1 to 5 of 5

Thread: count commas in a text field in Access

  1. #1
    Join Date
    Sep 2011
    Posts
    3

    count commas in a text field in Access

    Hi there.

    I'm working with an Access database and need to be able to count the number of commas (or comma separated words) in a text field in the table [Survey Data]. The field has numerous comma separated words.

    I've read a bit online that I could parse the field into multiple fields, or could possibly use CountCSWords to count the number of comma separated words. I don't see the CountCSWords function in the Expression Builder though. I'm pretty new (actually, very new) to Access though and have no idea how to do this. Is there a way that I can have this as an expression in a calculated field in a table or query? I'd really appreciate any help y'all can give me so I can get this t work.

  2. #2
    Join Date
    Jan 2006
    Posts
    605

    Re: count commas in a text field in Access

    The easiest way that I know is to use the Split function, take a look at the below example:

    Code:
    Public Function CountStringItems( _
       Items As String, _
       Delim As String _
    ) As Long
       Dim varaItems As Variant
       varaItems = Split(Items, Delim)
       CountStringItems = ArrayCount(varaItems)
    End Function
    
    Public Function ArrayCount(varArray As Variant)
       ArrayCount = UBound(varArray) - LBound(varArray) + 1
    End Function

  3. #3
    Join Date
    Sep 2011
    Posts
    3

    Re: count commas in a text field in Access

    Thanks!

    Where would I paste this code? In VB? And then how to I reference it in a table or query? Sorry, this is pretty new to me.

  4. #4
    Join Date
    Dec 2007
    Posts
    1,736

    Re: count commas in a text field in Access

    Well, I think that you will need to apply the code in two events of the form - The On Current Event of the Form and the On Change Event of the Textbox that you are verifying the data entry of. When building a query in Microsoft Access, you can use expressions to perform calculations with your data. The "Len" expression will count the number of characters in a specific field of your Access database file.

  5. #5
    Join Date
    Sep 2011
    Posts
    3

    Re: count commas in a text field in Access

    Ah, okay. Thanks - I'm starting to get it now.

    So basically, it's not possible to do what I want as a calculated field in a table or query - I'd have to do it in a form, right?

    Last question, I promise

Similar Threads

  1. Replies: 2
    Last Post: 23-02-2012, 02:54 PM
  2. Replies: 2
    Last Post: 06-01-2012, 04:15 PM
  3. Multi Field value field in Microsoft Access
    By Erubiel in forum Windows Software
    Replies: 3
    Last Post: 20-11-2009, 12:55 AM
  4. How to count number of text occurences in Excel column
    By Anas in forum Windows Software
    Replies: 3
    Last Post: 09-06-2009, 05:01 PM
  5. To access a text field from another form
    By Sanket07 in forum Software Development
    Replies: 6
    Last Post: 06-02-2009, 06:42 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,876,159.76437 seconds with 17 queries