vb 实时错误3705,对象打开时不允许操作! 5
PrivateSubCommand1_Click()Dimxingming1Dimxingbie1Dimjiguan1Dimshengri1Dimxueli1Dimzhu...
Private Sub Command1_Click()
Dim xingming1
Dim xingbie1
Dim jiguan1
Dim shengri1
Dim xueli1
Dim zhuanye1
Dim bumen1
Dim zhiwu1
Dim gongling1
Dim where
where = ""
xingming = Text1.Text
xingbie = Combo1.Text
jiguan = Text4.Text
shengri = Text3.Text
xueli = Text5.Text
zhuanye = Text6.Text
bumen = Text7.Text
zhiwu = Text8.Text
gongling = Text9.Text
xingming1 = Text20.Text
xingbie1 = Combo2.Text
jiguan1 = Text17.Text
shengri1 = Text18.Text
xueli1 = Text16.Text
zhuanye1 = Text15.Text
bumen1 = Text14.Text
zhiwu1 = Text13.Text
gongling1 = Text12.Text
'把输入文本框里的值赋给变量
If xingming <> "" Then
where = where & "AND xingming = '" & xingming & "'"
End If
If xingbie <> "" Then
where = where & "AND xingbie = '" & xingbie & "'"
End If
If jiguan <> "" Then
where = where & "AND jiguan = '" & jiguan & "'"
End If
If shengri <> "" Then
where = where & "AND shengri = '" & shengri & "'"
End If
If xueli <> "" Then
where = where & "AND xueli = '" & xueli & "'"
End If
If zhuanye <> "" Then
where = where & "AND zhuanye = '" & zhuanye & "'"
End If
If bumen <> "" Then
where = where & "AND bumen = '" & bumen & "'"
End If
If zhiwu <> "" Then
where = where & "AND zhiwu = '" & zhiwu & "'"
End If
If gongling <> "" Then
where = where & "AND gongling = '" & gongling & "'"
End If
'以上代码是为了表示把xingming,xingbie,jiguan等几个变量用布尔表达式来连接,然后把查询数据库的条件之一存在于where 中。
If where = "" Then
MsgBox "请输入源信息。", vbOKOnly, "提示"
Exit Sub
End If
'where为空,表示没有输入原信息,则显示提示信息框
where = Mid(where, 5, Len(where))
'去掉where前的and
Dim conn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim connstr As String
connstr = "provider=microsoft.jet.oledb.4.0;data source=shujuku.mdb"
Dim sql As String
sql = "select * from 员工信息 where " & where
conn.Open (connstr)
rs.Open sql, conn, 3, 3
If rs.Fields(0) = 0 Then
MsgBox "没有满足条件的记录", vbOKOnly, "提示"
Exit Sub
'如果没有填写查询条件,即where = "",则显示提示信息框!
Else
conn.Open (connstr)
sql = "update 员工信息 set xingming = '" & xingming1 & "',xingbie = '" & xingbie1 & "',jiguan = '" & jiguan1 & "',shengri = '" & shengri1 & "',xueli = '" & xueli1 & "',zhuanye = '" & zhuanye1 & "',bumen = '" & bumen1 & "',zhiwu = '" & zhiwu1 & "',gongling = '" & gongling1 & "' where" & where
rs.Open sql, conn, 3, 3
MsgBox "员工信息更新成功!", vbOKOnly, "提示"
End If
Exit Sub
end sub
错误指向conn.Open (connstr)这一句,去掉或者加上这一句都出这个错误
这是一个员工信息修改的窗体! 展开
Dim xingming1
Dim xingbie1
Dim jiguan1
Dim shengri1
Dim xueli1
Dim zhuanye1
Dim bumen1
Dim zhiwu1
Dim gongling1
Dim where
where = ""
xingming = Text1.Text
xingbie = Combo1.Text
jiguan = Text4.Text
shengri = Text3.Text
xueli = Text5.Text
zhuanye = Text6.Text
bumen = Text7.Text
zhiwu = Text8.Text
gongling = Text9.Text
xingming1 = Text20.Text
xingbie1 = Combo2.Text
jiguan1 = Text17.Text
shengri1 = Text18.Text
xueli1 = Text16.Text
zhuanye1 = Text15.Text
bumen1 = Text14.Text
zhiwu1 = Text13.Text
gongling1 = Text12.Text
'把输入文本框里的值赋给变量
If xingming <> "" Then
where = where & "AND xingming = '" & xingming & "'"
End If
If xingbie <> "" Then
where = where & "AND xingbie = '" & xingbie & "'"
End If
If jiguan <> "" Then
where = where & "AND jiguan = '" & jiguan & "'"
End If
If shengri <> "" Then
where = where & "AND shengri = '" & shengri & "'"
End If
If xueli <> "" Then
where = where & "AND xueli = '" & xueli & "'"
End If
If zhuanye <> "" Then
where = where & "AND zhuanye = '" & zhuanye & "'"
End If
If bumen <> "" Then
where = where & "AND bumen = '" & bumen & "'"
End If
If zhiwu <> "" Then
where = where & "AND zhiwu = '" & zhiwu & "'"
End If
If gongling <> "" Then
where = where & "AND gongling = '" & gongling & "'"
End If
'以上代码是为了表示把xingming,xingbie,jiguan等几个变量用布尔表达式来连接,然后把查询数据库的条件之一存在于where 中。
If where = "" Then
MsgBox "请输入源信息。", vbOKOnly, "提示"
Exit Sub
End If
'where为空,表示没有输入原信息,则显示提示信息框
where = Mid(where, 5, Len(where))
'去掉where前的and
Dim conn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim connstr As String
connstr = "provider=microsoft.jet.oledb.4.0;data source=shujuku.mdb"
Dim sql As String
sql = "select * from 员工信息 where " & where
conn.Open (connstr)
rs.Open sql, conn, 3, 3
If rs.Fields(0) = 0 Then
MsgBox "没有满足条件的记录", vbOKOnly, "提示"
Exit Sub
'如果没有填写查询条件,即where = "",则显示提示信息框!
Else
conn.Open (connstr)
sql = "update 员工信息 set xingming = '" & xingming1 & "',xingbie = '" & xingbie1 & "',jiguan = '" & jiguan1 & "',shengri = '" & shengri1 & "',xueli = '" & xueli1 & "',zhuanye = '" & zhuanye1 & "',bumen = '" & bumen1 & "',zhiwu = '" & zhiwu1 & "',gongling = '" & gongling1 & "' where" & where
rs.Open sql, conn, 3, 3
MsgBox "员工信息更新成功!", vbOKOnly, "提示"
End If
Exit Sub
end sub
错误指向conn.Open (connstr)这一句,去掉或者加上这一句都出这个错误
这是一个员工信息修改的窗体! 展开
1个回答
展开全部
sql = "select * from 员工信息 where " & where
conn.Open (connstr)
rs.Open sql, conn, 3, 3
If rs.Fields(0) = 0 Then
MsgBox "没有满足条件的记录", vbOKOnly, "提示"
Exit Sub
'如果没有填写查询条件,即where = "",则显示提示信息框!
Else
conn.Open (connstr)
你所说的出错,应该是ELSE后面的这一个吧?因为你在IF之前就OPEN过一次了,然后再来OPEN,肯定会有提示被打开了的。后面这一个应该是不用写的了。
conn.Open (connstr)
rs.Open sql, conn, 3, 3
If rs.Fields(0) = 0 Then
MsgBox "没有满足条件的记录", vbOKOnly, "提示"
Exit Sub
'如果没有填写查询条件,即where = "",则显示提示信息框!
Else
conn.Open (connstr)
你所说的出错,应该是ELSE后面的这一个吧?因为你在IF之前就OPEN过一次了,然后再来OPEN,肯定会有提示被打开了的。后面这一个应该是不用写的了。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询