标题: 请教,遍历一个查询,找出数量字段的空值,并提示.该如何做. [打印本页] 作者: liuweisunjing 时间: 2008-2-16 14:53 标题: 请教,遍历一个查询,找出数量字段的空值,并提示.该如何做. 这是我东拼西凑的代码,运行提示少参数.请高手指点一下.多谢了.
Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset
shuliang = "SELECT 订单明细.订单ID, 订单明细.数量 FROM 订单明细 GROUP BY 订单明细.订单ID, 订单明细.数量 HAVING (((订单明细.订单ID)=[forms]![订单]![订单ID]));"
rs.Open shuliang, CurrentProject.Connection, adOpenDynamic, adLockOptimistic
Do While rs.EOF
If IsNull(rs.Fields("数量")) = True Then
MsgBox "至少一条记录没有数量,请核对后保存", vbDefaultButton1
Else
rs.MoveNext
End If
Loop
Set rs = Nothing作者: haemon 时间: 2008-2-16 15:04
不如把库传上来, 这样好象无法调试, 也看不出哪的问题作者: liuweisunjing 时间: 2008-2-16 15:43
好的,请帮忙看看[attach]28458[/attach]作者: haemon 时间: 2008-2-16 16:00
shuliang = "SELECT 订单明细.订单ID, 订单明细.数量 FROM 订单明细 GROUP BY 订单明细.订单ID, 订单明细.数量 HAVING (((订单明细.订单ID)='" & [Forms]![订单]![订单ID] & "'));"作者: haemon 时间: 2008-2-16 16:01
[Forms]![订单]![订单ID]是变量呀!作者: liuweisunjing 时间: 2008-2-16 16:17
没有成功,不报错了,但判断不出数量有空值啊.作者: glw 时间: 2008-2-16 17:45
Do While rs.EOF
改为
do while not rs.eof作者: glw 时间: 2008-2-16 17:48
Private Sub Command41_Click()
Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset
shuliang = "SELECT 订单明细.订单ID, 订单明细.数量 FROM 订单明细 GROUP BY 订单明细.订单ID, 订单明细.数量 HAVING (((订单明细.订单ID)='" & [Forms]![订单]![订单ID] & "'));"
rs.Open shuliang, CurrentProject.Connection, adOpenDynamic, adLockOptimistic
Do While Not rs.EOF
If IsNull(rs.Fields("数量")) = True Then
MsgBox "至少一条记录没有数量,请核对后保存", vbDefaultButton1
Exit Do '加上这一句,不然死循环
Else
rs.MoveNext
End If
Loop
Set rs = Nothing
Me.Command37.SetFocus
Me.Command41.Enabled = False
Call bukebianji