Results 1 to 9 of 9
  1. #1
    theyad75 is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Nov 2014
    Posts
    13

    fuction like dcount in access

    im looking for function can use to count specific word in column from text


    example have records like

    id movie_title count



    1 the good the bad the 3
    2 the beauty and the beast 2
    3 the rock 1

    searching for criteria like "the" should have result

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    That will require VBA custom function that searches for the substring and parses the original string into multiple parts. Like:

    Code:
    Function CountSubstring(strInput As String, strSearch As String) As Integer
    While InStr(strInput, strSearch) > 0
        strInput = Mid(strInput, InStr(strInput, strSearch) + Len(strSearch) + 1)
        CountSubstring = CountSubstring + 1
    Wend
    End Function
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    theyad75 is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Nov 2014
    Posts
    13
    well i have vba function and work well as test but when i try the code in query asUser-defined function work but give me wrong answer .


  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Post your function code and the query SQL statement for analysis.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    theyad75 is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Nov 2014
    Posts
    13
    Public Function getWordCount(ByRef sSentence As String, ByRef sWord As String) As Integer
    Dim RegEx As Object
    Dim regexMatches As Object
    Dim oReturn AsVariant
    Set RegEx = CreateObject("VBScript.RegExp")
    RegEx.MultiLine = False
    RegEx.Global = True
    RegEx.IgnoreCase = False
    RegEx.Pattern = "[" sWord & "]+"
    Set regexMatches =RegEx.Execute(sSentence)
    getWordCount = regex
    Matches.Count
    End Function
    -----------------------
    SELECT Books.Title, getWordCount([Books]![Title],[Forms]![Form2]![txtCriteria]) AS WordCountFROM Books;
    Last edited by June7; 11-22-2014 at 06:43 PM.

  6. #6
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Why does your code create a VBScript object? I am not familiar with the code syntax you are using.

    Did you try the code I suggested?

    This is marked solved - is it?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    theyad75 is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Nov 2014
    Posts
    13
    yes yes and what you gave me work right amazing

  8. #8
    theyad75 is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Nov 2014
    Posts
    13
    tell me June7 what about mssql can i use the same code?

  9. #9
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    I don't understand. MS SQL is the backend and you have Access link to it? The code should not care what the tables are.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. Expected End Of Statement Dcount, Access 2003
    By DetrieZ in forum Queries
    Replies: 1
    Last Post: 07-09-2013, 04:50 PM
  2. dcount function - new to Access VBA
    By jillp in forum Programming
    Replies: 7
    Last Post: 09-20-2012, 06:35 AM
  3. Access 2007 Dcount
    By BeitersIT in forum Access
    Replies: 1
    Last Post: 04-21-2012, 01:20 PM
  4. Count fuction
    By funi.t in forum Access
    Replies: 3
    Last Post: 12-09-2011, 04:02 AM
  5. fuction elapsed time, expression builder
    By zac123 in forum Access
    Replies: 1
    Last Post: 08-05-2011, 02:21 PM

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