Access开发培训
网站公告
·Access专家课堂QQ群号:151711184    ·Access快速开发平台下载地址及教程    ·欢迎加入Access专家课堂微信群!    ·如何快速搜索本站文章|示例|资料    
您的位置: 首页 > 技术文章 > Access数据库-模块/函数/VBA

代码优化(二)

时 间:2017-12-26 08:18:42
作 者:杨雪   ID:42182  城市:南京
摘 要:代码优化
正 文:

源码:运行起来很慢。

strSQL = "Select HomestayName, BedScheduling, SexPreference, 剩余接待人数2, Area FROM qry_HomestaySelect " & _
             "where SexPreference like '*" & Me.[Sex] & "*' and Area in (select Headquarters from tbl_line where lineno=" & sqltext(Me.LineNo) & ")"
    Me.sfrChild.Form.RecordSource = strSQL
    Me.sfrChild.Form.Requery


优化代码:运行起来快了很多倍。

    Dim rst As Object
    Dim strSQL As String
    strSQL = "Select Headquarters FROM tbl_line Where [LineNo] = " & SQLText(Me.LineNo)
    Set rst = OpenAdoRecordset(strSQL)
    Dim strAreaList As String
    Do Until rst.EOF
        strAreaList = strAreaList & ",'" & rst!Headquarters & "'"
        rst.MoveNext
    Loop
    rst.Close
    If strAreaList <> "" Then strAreaList = " AND Area IN (" & Mid(strAreaList, 2) & ")"

    strSQL = " Select HomestayName, BedScheduling, SexPreference, 剩余接待人数2, Area" _
           & " FROM qry_HomestaySelect1 Where SexPreference Like '*" & Me.Sex & "*'" & strAreaList

    Me.sfrChild.Form.RecordSource = strSQL
    Me.sfrChild.Form.Requery



Access软件网QQ交流群 (群号:54525238)       Access源码网店

常见问答:

技术分类:

相关资源:

专栏作家

关于我们 | 服务条款 | 在线投稿 | 友情链接 | 网站统计 | 网站帮助