Access query how to call a custom function

Today we share with you Access query call a custom function.

In Access queries can call custom functions that can help us solve the practical work in some special query statistics.

Next, the problem with a small series of friends teach you call, let's look at an example.

Q: How can count the number of certain words appear in the lyrics?

1
The first step: to build the table
specific table shown below

Here Insert Picture Description

2
Step: write a custom function
specific function as follows. There is a knowledge, is the Split function, we revisit this later, want to mention here.
[code = VB]
Public Function WordFrequency (ByVal Lyric of As String, ByVal Word of As String) of As String
Dim ARR of As the Variant
Dim BRR of As the Variant
Dim I of As Long
Dim countChar of As Long
the If Lyric = "" Or Word = "" the Then the Exit Function
IF the InStrRev (Word, "|") = 0 the Then the Exit Function
ARR = Split (Word, "|")
the For I = 0 the To the UBound (ARR) -. 1
BRR = Split (Lyric, ARR (I))
countChar = the UBound ( BRR) - the LBound (BRR)
WordFrequency = WordFrequency & "" "& ARR (I) &" "" & "occurrence:" & vbCrLf & countChar
the Next I
End Function
[/ code]

3
The third step: to build a query
specific query we look at the screenshot below

Here Insert Picture Description

SQL statements:
the SELECT title, lyrics, word, WordFrequency ([lyrics], [word]) AS FROM word frequency table 2;

Finally, we look at the operating results

Here Insert Picture Description

Well, today will stop here, we go and try it.

Here Insert Picture Description

Published 10 original articles · won praise 8 · views 3827

Guess you like

Origin blog.csdn.net/weiisiceman/article/details/90182581