|
在用ACCESS编程中,若你想同时查询多个条件,例如:
在一张数据表中,
-----------------------
|地区|客户|销售额|数量|
|---------------------|
|上海|A |8000 |500 |
|北京|B |6000 |600 |
|江苏|C |5000 |300 |
|浙江|D |2000 |300 |
-----------------------
若在以上这个表中,我想同时查找上海与北京的销售情况,则可以利用mlike函数
为:mlike(上海;北京)如此输入即可;mlike函数如下
Function mLike(Param As Variant, Cond As Variant) As Boolean
On Error GoTo mLike_Err
Dim stn As String, stl As String, n As Integer, stlen As Integer
Dim stParam As String, stCond As String
If IsNull(Param) Or IsNull(Cond) Then
mLike = False
Exit Function
End If
stParam = Trim$(UCase$(Param))
stCond = Trim$(UCase$(Cond))
If stParam Like stCond Then
mLike = True
Exit Function
End If
stn = Trim$(stCond)
stlen = Len(stCond)
n = InStr(1, stn, ";")
While n <> 0
If stParam Like stn Then
mLike = True
Exit Function
End If
n = InStr(1, stn, ";")
If n <= 1 Then
mLike = False
Exit Function
End If
stl = Left$(stn, n - 1)
stn = Right$(stn, stlen - n)
stlen = Len(stn)
If stParam Like stl Then
mLike = True
Exit Function
End If
Wend
mLike = False
Exit Function
mLike_Err:
MsgBox "Error In mLike....." & Err.Description
mLike = False
Exit Function
End Function |
|