vba【查询功能】按A-Z首字母查询(上)

HI,大家好!

之前我给大家分享过一个示例,如下图:

 

这个示例我们可以看到可以按字母A-Z,数字0-9的一个筛选编码,同时可以选择编号后可以显示对应的明细数据。

接下去我就来教大家怎么来做这个示例,这个示例东西比较多,所以我们将他分解一下,今天我们先来做左上角的功能,如下图:

鼠标在放到对应的标签上后,文字对应的变红,且标签有浮动的效果,点击后列表框的数据发生变化,接下去我们来看一下怎么实现这些功能。

01、创建窗体

创建一个窗体,然后在左上角放上26个英文字母的标签,还有数字,没错你没有看错,那些英文字母就是标签控件,需要一个一个的放好,做开发要有耐心,放好这些控件后,在右下角放一个列表框(infoList),右边放上一个子窗体控件(frmChild)。

 

02、添加代码

这次在窗体里添加两个函数

标签移动通用函数

Private Function lblMove(intCurrButton As String)
    On Error GoTo ErrorHandler
    Static intLastClicked As String, tmp1
    Dim ctl As Control
    If intCurrButton <> intLastClicked Then
        intLastClicked = intCurrButton
        For Each ctl In Me
            If ctl.ControlType = acLabel Then
                ctl.SpecialEffect = 0
                ctl.ForeColor = 0
                ctl.FontWeight = 400
            End If
        Next

        tmp1 = intLastClicked

        Select Case intLastClicked
        Case "ZET9"
            Me(intCurrButton).SpecialEffect = 1
            '        Me.(intCurrButton).ForeColor = 17777215
            Me(intCurrButton).FontWeight = 900
            Me(intCurrButton).ForeColor = 255

        Case "ALL"
            Me(intCurrButton).SpecialEffect = 1
            '        Me(intCurrButton).ForeColor = 17777215
            Me(intCurrButton).FontWeight = 900
            Me(intCurrButton).ForeColor = 255

        Case "OTH"
            Me(intCurrButton).SpecialEffect = 1
            '        Me(intCurrButton).ForeColor = 17777215
            Me(intCurrButton).FontWeight = 900
            Me(intCurrButton).ForeColor = 255

        Case tmp1
            Me(intCurrButton).SpecialEffect = 1
            '        Me(intCurrButton).ForeColor = 17777215
            Me(intCurrButton).FontWeight = 900
            Me(intCurrButton).ForeColor = 255

        Case 0
            Me(intCurrButton).SpecialEffect = 0
            Me(intCurrButton).ForeColor = 0
            Me(intCurrButton).FontWeight = 400

        End Select
        intCurrButton = intLastClicked
    End If
ExitHere:
    Exit Function
ErrorHandler:
    MsgBox Err.Description, vbCritical
    Resume ExitHere
End Function

标签点击通用函数

Private Function lblClick(intCurrButton As String)
    On Error GoTo ErrorHandler
    Dim strSQL As String
    Me.infoList.RowSource = ""
    Select Case intCurrButton
    Case "All"
        strSQL = "select distinct 拼音码 from qry商品信息 where 拼音码 order by 拼音码"
    Case "OTH"
        strSQL = "select distinct 拼音码 from qry商品信息 where 拼音码 not like '[0-9]*' and 拼音码 not like '[A-Z]*' order by 拼音码"
    Case "ZET9"
        strSQL = "select distinct 拼音码 from qry商品信息 where 拼音码 like '#*' order by 拼音码"
    Case Else
        strSQL = "select distinct 拼音码 from qry商品信息 where 拼音码 like '" & intCurrButton & "*' order by 拼音码"
    End Select
    'Debug.Print strSQL
    Me.infoList.RowSource = strSQL
ExitHere:
    Exit Function
ErrorHandler:
    MsgBox Err.Description, vbCritical
    Resume ExitHere
End Function

 

注意:这里的表也要自己相应的添加一下。

 

函数添加完成后,像下图一样给每个标签添加对应的代码

这个是函数的一个调用方式。

 

 

03、运行测试

最后一步就是运行窗体测试了。

大家快去测试一下吧。

最后是广告时间,大家可以关注我的B站,Access开发视频首发都在我的B站。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

易登软件Access开发

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值