设为首页收藏本站Access中国

Office中国论坛/Access中国论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

返回列表 发新帖
查看: 887|回复: 3
打印 上一主题 下一主题

[Access本身] 代码运行速度

[复制链接]
跳转到指定楼层
1#
发表于 2006-8-19 01:14:00 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
以下代码运行速度很慢,在下是根据这个贴子改的

http://www.office-cn.net/forum.php?mod=viewthread&tid=32120&replyID=&skin=1

但效果不明显,故来请教高手了

Private Sub Detail_Print(Cancel As Integer, PrintCount As Integer)
Dim p, f, b, t, m As Long
    p = Nz(DLookup("lanQty", "roduceStatustwo", "roductionName='" & Me.ProductionName & "'and Nian='" & Me.Nian & "'and Yue=1"), 0)
    f = Nz(DLookup("FactQty", "ProduceStatustwo", "ProductionName='" & Me.ProductionName & "'and Nian='" & Me.Nian & "'and Yue=1"), 0)
    b = IIf(f = 0, 0, f - p)
        Me.Text56 = p: Me.Text80 = f: Me.Text11 = b: m = b
    p = Nz(DLookup("PlanQty", "ProduceStatustwo", "ProductionName='" & Me.ProductionName & "'and Nian='" & Me.Nian & "'and Yue=2"), 0)
    f = Nz(DLookup("FactQty", "ProduceStatustwo", "ProductionName='" & Me.ProductionName & "'and Nian='" & Me.Nian & "'and Yue=2"), 0)
    b = IIf(f = 0, 0, f - p)
        Me.Text57 = p: Me.Text81 = f: Me.Text13 = b: m = m + b
    p = Nz(DLookup("PlanQty", "ProduceStatustwo", "ProductionName='" & Me.ProductionName & "'and Nian='" & Me.Nian & "'and Yue=3"), 0)
    f = Nz(DLookup("FactQty", "ProduceStatustwo", "ProductionName='" & Me.ProductionName & "'and Nian='" & Me.Nian & "'and Yue=3"), 0)
    b = IIf(f = 0, 0, f - p)
        Me.Text58 = p: Me.Text82 = f: Me.Text14 = b: m = m + b
    p = Nz(DLookup("PlanQty", "ProduceStatustwo", "ProductionName='" & Me.ProductionName & "'and Nian='" & Me.Nian & "'and Yue=4"), 0)
    f = Nz(DLookup("FactQty", "ProduceStatustwo", "ProductionName='" & Me.ProductionName & "'and Nian='" & Me.Nian & "'and Yue=4"), 0)
    b = IIf(f = 0, 0, f - p)
        Me.Text59 = p: Me.Text83 = f: Me.Text15 = b: m = m + b
    p = Nz(DLookup("PlanQty", "ProduceStatustwo", "ProductionName='" & Me.ProductionName & "'and Nian='" & Me.Nian & "'and Yue=5"), 0)
    f = Nz(DLookup("FactQty", "ProduceStatustwo", "ProductionName='" & Me.ProductionName & "'and Nian='" & Me.Nian & "'and Yue=5"), 0)
    b = IIf(f = 0, 0, f - p)
        Me.Text60 = p: Me.Text84 = f: Me.Text16 = b: m = m + b
    p = Nz(DLookup("PlanQty", "ProduceStatustwo", "ProductionName='" & Me.ProductionName & "'and Nian='" & Me.Nian & "'and Yue=6"), 0)
    f = Nz(DLookup("FactQty", "ProduceStatustwo", "ProductionName='" & Me.ProductionName & "'and Nian='" & Me.Nian & "'and Yue=6"), 0)
    b = IIf(f = 0, 0, f - p)
        Me.Text61 = p: Me.Text85 = f: Me.Text17 = b: m = m + b
    p = Nz(DLookup("PlanQty", "ProduceStatustwo", "ProductionName='" & Me.ProductionName & "'and Nian='" & Me.Nian & "'and Yue=7"), 0)
    f = Nz(DLookup("FactQty", "ProduceStatustwo", "ProductionName='" & Me.ProductionName & "'and Nian='" & Me.Nian & "'and Yue=7"), 0)
    b = IIf(f = 0, 0, f - p)
        Me.Text62 = p: Me.Text86 = f: Me.Text18 = b: m = m + b
    p = Nz(DLookup("PlanQty", "ProduceStatustwo", "ProductionName='" & Me.ProductionName & "'and Nian='" & Me.Nian & "'and Yue=8"), 0)
    f = Nz(DLookup("FactQty", "ProduceStatustwo", "ProductionName='" & Me.ProductionName & "'and Nian='" & Me.Nian & "'and Yue=8"), 0)
    b = IIf(f = 0, 0, f - p)
        Me.Text63 = p: Me.Text87 = f: Me.Text19 = b: m = m + b
    p = Nz(DLookup("PlanQty", "ProduceStatustwo", "ProductionName='" & Me.ProductionName & "'and Nian='" & Me.Nian & "'and Yue=9"), 0)
    f = Nz(DLookup("FactQty", "ProduceStatustwo", "ProductionName='" & Me.ProductionName & "'and Nian='" & Me.Nian & "'and Yue=9"), 0)
    b = IIf(f = 0, 0, f - p)
        Me.Text64 = p: Me.Text88 = f: Me.Text20 = b: m = m + b
    p = Nz(DLookup("PlanQty", "ProduceStatust
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享分享 分享淘帖 订阅订阅
2#
发表于 2006-8-19 01:25:00 | 只看该作者
Dlookup函数本身运行就很慢,你用那么多当然就更慢了。怎么不使用ADO来解决呢?
3#
发表于 2006-8-19 01:45:00 | 只看该作者
也许是你的数据结构不好,导致必须用这么多的判断,建立网状数据结构应该一两次查询就够了。
4#
发表于 2006-8-19 01:48:00 | 只看该作者
尽量少用iif 和 Dlookup
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-11-12 06:49 , Processed in 0.138977 second(s), 28 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表