Office中国论坛/Access中国论坛

标题: 代码运行速度 [打印本页]

作者: zyz218    时间: 2006-8-19 01:14
标题: 代码运行速度
以下代码运行速度很慢,在下是根据这个贴子改的

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
作者: fan0217    时间: 2006-8-19 01:25
Dlookup函数本身运行就很慢,你用那么多当然就更慢了。怎么不使用ADO来解决呢?
作者: 情比金坚    时间: 2006-8-19 01:45
也许是你的数据结构不好,导致必须用这么多的判断,建立网状数据结构应该一两次查询就够了。
作者: andymark    时间: 2006-8-19 01:48
尽量少用iif 和 Dlookup




欢迎光临 Office中国论坛/Access中国论坛 (http://www.office-cn.net/) Powered by Discuz! X3.3