新手问题! 关于With object 的问题!

sanwaxubin 2004-03-25 07:40:54
我在一过程中这样写的,但总是报错,
Dim nRst As New ADODB.Recordset
Dim tRst As New ADODB.Recordset
Dim Xitm as listitem
Dim strSQL1 As String
Dim strSQL2 As String

strsql1="select * From ABC"

Set nRst = gConn.Execute(strSQL1)

ListView1.ListItems.Clear

If nRst.BOF And nRst.EOF Then
MsgBox "test"
Else
nRst.MoveFirst
For i = 1 To nRst.RecordCount
Set xItem = ListView1.ListItems.Add(, , Trim(nRst!ZYDM), "YJK", "YJK")
With xItem
.SubItems(1) = Trim(nRst!FKFS) & ""
.SubItems(2) = Trim(Format(nRst!YJJE, "0.00")) & ""
.SubItems(3) = Trim(nRst!SJ)
.SubItems(4) = Trim(nRst!CZYMC)
strSQL2="Select SUM(ADBD) ADBD From DEF Where ZYDM='"&TRIM(NRST!ZYDM) &"'"
SET tRst=gConn.Execute(strSQL2)

.SubItems(5)=tRst!ADBD

End With
nRst.MoveNext
Next
END IF
...全文
104 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
sanwaxubin 2004-04-04
  • 打赏
  • 举报
回复
问题已经解决,但是通过别的方法来解决的!感谢大家!
northwolves 2004-03-26
  • 打赏
  • 举报
回复
TRY:

Dim nRst As New ADODB.Recordset
Dim tRst As New ADODB.Recordset
Dim Xitm as listitem
Dim strSQL1 As String
Dim strSQL2 As String

strsql1="select * From ABC"

Set nRst = gConn.Execute(strSQL1)

ListView1.ListItems.Clear

If nRst.BOF And nRst.EOF Then
MsgBox "test"
Else
nRst.MoveFirst
DO WHILE NOT NRST.EOF
Set xItem = ListView1.ListItems.Add(, , Trim(nRst!ZYDM), "YJK", "YJK")
With xItem
.SubItems(1) = Trim(nRst!FKFS) & ""
.SubItems(2) = Trim(Format(nRst!YJJE, "0.00")) & ""
.SubItems(3) = Trim(nRst!SJ)
.SubItems(4) = Trim(nRst!CZYMC)
strSQL2="Select SUM(ADBD) ADBD From DEF Where ZYDM='"&TRIM(NRST!ZYDM) &"'"
SET tRst=gConn.Execute(strSQL2)

.SubItems(5)=tRst!ADBD

End With
nRst.MoveNext
LOOP
END IF
sanwaxubin 2004-03-26
  • 打赏
  • 举报
回复
谢谢,xzp1030(向星星前进) 让您费神了,我试过还是一样的,报同样的错!
xzp1030 2004-03-26
  • 打赏
  • 举报
回复
看了半天你试试这样:
Dim nRst As New ADODB.Recordset
Dim tRst As New ADODB.Recordset
Dim Xitm as listitem
Dim strSQL1 As String
Dim strSQL2 As String

strsql1="select * From ABC"

Set nRst = gConn.Execute(strSQL1)

ListView1.ListItems.Clear

If nRst.EOF Then
MsgBox "test"
Else
nRst.MoveFirst
For i = 1 To nRst.RecordCount
Set xItem = ListView1.ListItems.Add(, , Trim(nRst!ZYDM), "YJK", "YJK")
With xItem
.SubItems(1) = Trim(nRst!FKFS) & ""
.SubItems(2) = Trim(Format(nRst!YJJE, "0.00")) & ""
.SubItems(3) = Trim(nRst!SJ)
.SubItems(4) = Trim(nRst!CZYMC)
strSQL2="Select SUM(ADBD) ADBD From DEF Where ZYDM='"&TRIM(NRST!ZYDM) &"'"
SET tRst=gConn.Execute(strSQL2)

.SubItems(5)=tRst!ADBD

End With
nRst.MoveNext
Next
END IF
sanwaxubin 2004-03-25
  • 打赏
  • 举报
回复
帮帮忙啊,up
sanwaxubin 2004-03-25
  • 打赏
  • 举报
回复
报WITH 没有end with 块的错!
victorycyz 2004-03-25
  • 打赏
  • 举报
回复

在哪个位置报错?报什么类型错误?

7,763

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧