标题:Do While Not mrc.EO语句F错误不知如何修改?????????
取消只看楼主
j11b
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2007-9-16
 问题点数:0 回复次数:8 
Do While Not mrc.EO语句F错误不知如何修改?????????

程序段如下:本人菜鸟程序调了好长时间了,现在急用啊!!在线等啊
Private Sub cmdexit_Click()
Unload Me
End Sub

Private Sub cmdinquire_Click()
Dim txtsql As String
Dim msgtext As String
Dim dd(4) As Boolean
Dim mrc As ADODB.Recordset
'组合sql语句
txtsql = "select * from worker_info where"

'判断是否选择胸卡号查询方式
If Check1(0).Value Then
If Trim(txtid.Text) = "" Then
smeg = "胸卡号不能为空!"
MsgBox smeg, vbOKOnly + vbExclamation, "警告"
txtid.SetFocus
Exit Sub
Else

'判断输入胸卡号是否为数字
If Not IsNumeric(Trim(txtid.Text)) Then
MsgBox "胸卡号请输入数字!", vbOKOnly + vbExclamation, "警告"
Exit Sub
txtid.SetFocus
End If

dd(0) = True
'组合查询语句
txtsql = txtsql & "id='" & Trim(txtid.Text) & "'"
End If
End If

'判断是否选择姓名查询方式
If Check1(1).Value Then
If Trim(txtname.Text) = "" Then
smeg = "姓名不能为空!"
MsgBox smeg, vbOKOnly + vbExclamation, "警告"
txtname.SetFocus
Exit Sub
Else

dd(1) = True
If dd(0) Then
'组合查询语句
txtsql = txtsql & "and name='" & txtname.Text & "'"
Else
txtsql = txtsql & "name='" & txtname.Text & "'"
End If
End If
End If

'判断是否选择工段查询方式
If Check1(2).Value Then
If Trim(txtgongduan.Text) = "" Then
smeg = "工段不能为空!"
MsgBox smeg, vbOKOnly + vbExclamation, "警告"
txtgongduan.SetFocus
Exit Sub
Else
dd(2) = True
If dd(0) Or dd(1) Then
txtsql = txtsql & "and gongduan='" & txtgongduan.Text & "'"
Else
txtsql = txtsql & "gongduan='" & txtgongduan.Text & "'"
End If
End If
End If

'判断是否设置查询方式
If Not (dd(0) Or dd(1) Or dd(2) Or dd(3)) Then
MsgBox "请选择查询方式!", vbOKOnly + vbExclamation, "警告"
Exit Sub
End If
'查询所有满足条件的内容
txtsql = txtsql & "order by id'"
Set mrc = executesql(txtsql, msgtext)
With myflexgrid1
.Rows = 2
.CellAlignment = 4
.TextMatrix(1, 0) = "姓名"
.TextMatrix(1, 1) = "胸卡号"
.TextMatrix(1, 2) = "性别"
.TextMatrix(1, 3) = "出生日期"
.TextMatrix(1, 4) = "工段"
.TextMatrix(1, 5) = "职务"
.TextMatrix(1, 6) = "政治面貌"
.TextMatrix(1, 7) = "文化程度"

Do While Not mrc.EOF 报错'91'对象变量或with块变量未设置
.Rows = Rows + 1
.CellAlignment = 4
.TextMatrix(.Rows - 1, 0) = mrc.Fields(0)
.TextMatrix(.Rows - 1, 1) = mrc.Fields(1)
.TextMatrix(.Rows - 1, 2) = mrc.Fields(2)
.TextMatrix(.Rows - 1, 3) = Format(mrc.Fields(3), "yyyy-mm-dd")
.TextMatrix(.Rows - 1, 4) = mrc.Fields(4)
.TextMatrix(.Rows - 1, 5) = mrc.Fields(5)
.TextMatrix(.Rows - 1, 6) = mrc.Fields(6)
.TextMatrix(.Rows - 1, 7) = mrc.Fields(7)

mrc.MoveNext
Loop
End With

mrc.Close

End Sub

搜索更多相关主题的帖子: mrc While 语句 Not 
2007-09-16 14:33
j11b
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2007-9-16
得分:0 
执行的代码???
我是自学的,不是太懂.
2007-09-16 16:12
j11b
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2007-9-16
得分:0 
我看了程序里面没有"'",为什么会显示出来,我也不是很清楚??
2007-09-16 16:19
j11b
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2007-9-16
得分:0 
txtsql = "select * from worker_info where"

这句不是查询语句吗?
我现在有点蒙了!
2007-09-16 16:22
j11b
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2007-9-16
得分:0 
没有
2007-09-16 16:23
j11b
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2007-9-16
得分:0 

是不是没连上数据库啊?
我看有的说增加:  set mrc = new adodb.recordset
mrc.open
这个我试过了,不好用,还是报同样的错误. 

2007-09-16 16:28
j11b
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2007-9-16
得分:0 
Public Function ExecuteSQL(ByVal SQL _
As String, MsgString As String) _
As ADODB.Recordset
'executes SQL and returns Recordset
Dim cnn As ADODB.Connection
Dim rst As ADODB.Recordset
Dim sTokens() As String

On Error GoTo ExecuteSQL_Error

sTokens = Split(SQL)
Set cnn = New ADODB.Connection
cnn.Open ConnectString
If InStr("INSERT,DELETE,UPDATE", _
UCase$(sTokens(0))) Then
cnn.Execute SQL
MsgString = sTokens(0) & _
" query successful"
Else
Set rst = New ADODB.Recordset
rst.Open Trim$(SQL), cnn, _
adOpenKeyset, _
adLockOptimistic
'rst.MoveLast 'get RecordCount
Set ExecuteSQL = rst
MsgString = "查询到" & rst.RecordCount & _
" 条记录 "
End If
ExecuteSQL_Exit:
Set rst = Nothing
Set cnn = Nothing
Exit Function

ExecuteSQL_Error:
MsgString = "查询错误: " & _
Err.Description
Resume ExecuteSQL_Exit
End Function

这是模块里的一段代码,麻烦你帮我看看,
至于你让我看的那个帖子,我看过了,我并不是等现成的,我没有那个意思.
2007-09-16 16:49
j11b
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2007-9-16
得分:0 
Public Function ConnectString() _
As String

ConnectString = "FileDSN=studentinfo.dsn;UID=sa;PWD="
End Function

理论知识不是很扎实,你就告诉我得了,我现在看书来不及了.
我破坏了论坛的创建初衷了吧!
2007-09-16 17:02
j11b
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2007-9-16
得分:0 

我自己看书吧,我是不会,你说的那些问题我现在理解不了.谢谢你!!!

2007-09-16 17:09



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-170358-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.680533 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved