设为首页收藏本站Access中国

Office中国论坛/Access中国论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

Access实现同时输入多个条件的模糊查询源码

2002-6-14 22:10| 发布者: admin| 查看: 1243| 评论: 3|原作者: sdlhlsd|来自: www.office-cn.net

摘要: 在用ACCESS编程中,若你想同时查询多个条件,例如: 在一张数据表中, ----------------------- |地区|客户|销售额|数量| |---------------------| |上海|A|8000 |500 | |北京|B|6000 |600 | |江苏|C|5000 |300 | ...
在用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
发表评论

最新评论

引用 youshanzx 2002-6-15 06:57
又学一招,谢谢了!



                                           ------------------------------------
                                              勿以恶小而为之,勿以善小而不为
引用 zhuyiwen 2002-6-15 07:37
好,收藏!
引用 chengweibing 2002-6-15 23:20
高手所体现的心灵之美!!!谢谢了……

查看全部评论(3)

QQ|站长邮箱|小黑屋|手机版|Office中国/Access中国 ( 粤ICP备10043721号-1 )  

GMT+8, 2024-4-26 17:46 , Processed in 0.106787 second(s), 23 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

返回顶部