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

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

王林
Release: 2020-12-07 16:06:16
forward
3147 people have browsed it

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]
Copy after login

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!

Related labels:
source:csdn.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template