Home  >  Article  >  Topics  >  What is the method of calling custom function in access query?

What is the method of calling custom function in access query?

王林
王林forward
2020-12-07 16:06:163071browse

What is the method of calling custom function in access query?

You can directly call custom functions in Access queries, which can help us solve some special query statistics in actual work.

(Related recommendations: access database learning)

Example:

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

Step 1: Create a table

See the figure below for the specific table

What is the method of calling custom function in access query?

##Step 2: Write a custom function

The specific functions are as follows. There is a knowledge point here, which is the Split function. We will talk about this later, but I will mention it here first.

[code=vb]
Public Function WordFrequency(ByVal Lyric As String, ByVal Word As String) As String
Dim arr As Variant
Dim brr As Variant
Dim i As Long
Dim countChar As Long
If Lyric = “” Or Word = “” Then Exit Function
If InStrRev(Word, “|”) = 0 Then Exit Function
arr = Split(Word, “|”)
For i = 0 To UBound(arr) - 1
brr = Split(Lyric, arr(i))
countChar = UBound(brr) - LBound(brr)
WordFrequency = WordFrequency & ““” & arr(i) & “”” & “出现次数:” & countChar & vbCrLf
Next i
End Function
[/code]

Step 3: Build a query

For specific queries, let’s look at the screenshot below

What is the method of calling custom function in access query?

SQL statement:

SELECT song title, lyrics, word segmentation, WordFrequency([lyrics],[word segmentation]) AS word frequency FROM Table 2;

Finally, let’s take a look at the running results

What is the method of calling custom function in access query?

The above is the detailed content of What is the method of calling custom function in access query?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:csdn.net. If there is any infringement, please contact admin@php.cn delete