我有一个文本字段Ran
,并且我希望能够使用RanKeyNo5
字段中出现的指定数量的字母(等值的2个数字)来更新字段Ran
(更新查询)。字母按在Ran
中出现的顺序排列。
例如,如果Ran
包含BFHCIEALGJDK
,则答案将是0203050104
。
我在代码中放置了消息框来监视值,它似乎可以正常工作,但是表没有更新。
查询,“更新为”:
KeyNo([Ran],5)
Public Function KeyNo(myStr As String, intLen As Integer) As String
Dim RandomString As String, strLetter As String, PosNo As Integer, LetSelect As String, LetNo As String, Count As Integer
RandomString = "00"
PosNo = 1
Count = Len(myStr)
'MsgBox myStr
Dim i As Long
For i = 1 To Count
LetSelect = Mid(myStr, PosNo, 1)
If LetSelect = "A" Then
LetNo = "01"
ElseIf LetSelect = "B" Then
LetNo = "02"
ElseIf LetSelect = "C" Then
LetNo = "03"
ElseIf LetSelect = "D" Then
LetNo = "04"
ElseIf LetSelect = "E" Then
LetNo = "05"
ElseIf LetSelect = "F" Then
LetNo = "06"
ElseIf LetSelect = "G" Then
LetNo = "07"
ElseIf LetSelect = "H" Then
LetNo = "08"
ElseIf LetSelect = "I" Then
LetNo = "09"
ElseIf LetSelect = "J" Then
LetNo = "10"
ElseIf LetSelect = "K" Then
LetNo = "11"
ElseIf LetSelect = "L" Then
LetNo = "12"
ElseIf LetSelect = "M" Then
LetNo = "13"
ElseIf LetSelect = "N" Then
LetNo = "14"
ElseIf LetSelect = "O" Then
LetNo = "15"
ElseIf LetSelect = "P" Then
LetNo = "16"
ElseIf LetSelect = "Q" Then
LetNo = "17"
ElseIf LetSelect = "R" Then
LetNo = "18"
ElseIf LetSelect = "S" Then
LetNo = "19"
ElseIf LetSelect = "T" Then
LetNo = "20"
ElseIf LetSelect = "U" Then
LetNo = "21"
ElseIf LetSelect = "V" Then
LetNo = "22"
ElseIf LetSelect = "W" Then
LetNo = "23"
ElseIf LetSelect = "X" Then
LetNo = "24"
ElseIf LetSelect = "Y" Then
LetNo = "25"
ElseIf LetSelect = "Z" Then
LetNo = "26"
End If
If Val(LetNo) <= intLen Then
RandomString = RandomString & LetNo
' MsgBox RandomString
End If
PosNo = PosNo + 1
Next
RandomString = Mid(RandomString, 3, intLen * 2)
End Function
最佳答案
它不返回任何内容,因为函数未设置为返回任何内容。最后一行应该是:KeyNo = Mid(RandomString, 3, intLen * 2)