设为首页收藏本站Access中国

Office中国论坛/Access中国论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

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

[模块/函数] 如何结束循环查询

[复制链接]
跳转到指定楼层
1#
发表于 2011-6-29 11:56:24 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
做的一个查询,中间有段用DO UNTIL----LOOP 进行反复查询,直到查询不记录时就停止,请教停止的条件如何设?

Private Sub Command0_Click()
Dim L As Integer
Dim Qty1 As Integer
Dim Item As Integer
Dim Fdate As Date
Dim FWEEK As Integer


Item = 4375
Fdate = 2011 - 6 - 28
L = 0
Qty1 = 1
FWEEK = 1
Dim sql As String


sql = "insert into R (item,brand,part_no,QTY,leve,sid,fdate,fweek) select " & Item & " ,t_icitem.fname as brand,t_icitem.fshortnumber as part_no," & Qty1 & "," & L & ",right(10000+t_icitem.fitemid,4)," & Fdate & "," & FWEEK & " from DBO_t_icitem AS T_ICITEM where fitemid=" & Item
DoCmd.RunSQL sql
Dim n As Integer
Do Until ??(结束条件)
  L = L + 1
  
  
sql = "insert into R  (item,brand,part_no,QTY,leve,sid,fdate,fweek) select t_icitem.fitemid,t_icitem.fname,t_icitem.fshortnumber,icbomchild.fauxqty*" & Qty1 & " as Qty," & L & ",r.sid & ','& right(10000+t_icitem.fitemid,4), " & Fdate & " , " & FWEEK & " from DBO_t_icitem AS t_icitem,DBO_icbom AS ICBOM ,DBO_icbomchild AS ICBOMCHILD, r  where R.leve = " & L - 1 & " And R.item = ICBOM.fitemid and icbom.FUSESTATUS=1072 and icbom.finterid=icbomchild.finterid and icbomchild.fitemid=t_icitem.fitemid"

DoCmd.RunSQL sql




Loop
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享分享 分享淘帖 订阅订阅
2#
发表于 2011-6-29 14:31:20 | 只看该作者
因为RunSQL只是执行动作查询,这里无法获取要操作的是多少个记录,所以...在执行RunSQL命令之前可以先用Rs打开一个加L条件的查询,判断下Rs的RecordCount,如果是0,就Exit Do
3#
发表于 2011-6-29 17:21:58 | 只看该作者
本帖最后由 todaynew 于 2011-6-29 17:22 编辑
tianya0073 发表于 2011-6-29 11:56
做的一个查询,中间有段用DO UNTIL----LOOP 进行反复查询,直到查询不记录时就停止,请教停止的条件如何设? ...


dcount("*","R")-L=0
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-11-17 14:14 , Processed in 0.082655 second(s), 27 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

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