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
##Step 2: Write a custom functionThe 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 queryFor specific queries, let’s look at the screenshot below 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
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!