Office中国论坛/Access中国论坛

标题: 如何结束循环查询 [打印本页]

作者: tianya0073    时间: 2011-6-29 11:56
标题: 如何结束循环查询
做的一个查询,中间有段用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
作者: 咱家是猫    时间: 2011-6-29 14:31
因为RunSQL只是执行动作查询,这里无法获取要操作的是多少个记录,所以...在执行RunSQL命令之前可以先用Rs打开一个加L条件的查询,判断下Rs的RecordCount,如果是0,就Exit Do
作者: todaynew    时间: 2011-6-29 17:21
本帖最后由 todaynew 于 2011-6-29 17:22 编辑
tianya0073 发表于 2011-6-29 11:56
做的一个查询,中间有段用DO UNTIL----LOOP 进行反复查询,直到查询不记录时就停止,请教停止的条件如何设? ...


dcount("*","R")-L=0




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