VB 对象关闭时不允许操作
添加属性记录提示添加成功,点击确定后跳出错误“对象关闭时不允许操作”代码如下:PrivateSubCommand1_Click()DimrsAsADODB.RecordS...
添加属性记录 提示添加成功,点击确定后跳出错误“对象关闭时不允许操作”
代码如下:
Private Sub Command1_Click()
Dim rs As ADODB.RecordSet
If Trim(Text1.Text) = "" Then
MsgBox "请输入监测点编号!", vbOKOnly + vbExclamation, "警告"
Exit Sub
Text1.SetFocus
Else
Set rs = ExcSQL("select * from 2010年6月水质监测成果")
While (rs.EOF = False)
If Trim(rs.Fields(0)) = Trim(Text1.Text) Then
MsgBox "此监测点已存在,请重新输入!", vbOKOnly + vbExclamation, "警告"
Text1.SetFocus
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
Text5.Text = ""
Text6.Text = ""
Text7.Text = ""
Text8.Text = ""
Text10.Text = ""
Text11.Text = ""
Text12.Text = ""
Text13.Text = ""
Text14.Text = ""
Text15.Text = ""
Text16.Text = ""
Text17.Text = ""
Text18.Text = ""
Text19.Text = ""
Exit Sub
Else
rs.AddNew
rs.Fields(0) = Trim(Text1.Text)
rs.Fields(1) = Trim(Text2.Text)
rs.Fields(2) = Trim(Text3.Text)
rs.Fields(3) = Trim(Text4.Text)
rs.Fields(4) = Trim(Text5.Text)
rs.Fields(5) = Trim(Text6.Text)
rs.Fields(6) = Trim(Text7.Text)
rs.Fields(7) = Trim(Text8.Text)
rs.Fields(8) = Trim(Text10.Text)
rs.Fields(9) = Trim(Text11.Text)
rs.Fields(10) = Trim(Text12.Text)
rs.Fields(11) = Trim(Text13.Text)
rs.Fields(12) = Trim(Text14.Text)
rs.Fields(13) = Trim(Text15.Text)
rs.Fields(14) = Trim(Text16.Text)
rs.Fields(15) = Trim(Text17.Text)
rs.Fields(16) = Trim(Text18.Text)
rs.Fields(17) = Trim(Text19.Text)
rs.MoveNext
rs.Close
Me.Hide
MsgBox "添加成功!", vbOKOnly + vbExclamation, "添加"
End If
Wend
End If
End Sub 展开
代码如下:
Private Sub Command1_Click()
Dim rs As ADODB.RecordSet
If Trim(Text1.Text) = "" Then
MsgBox "请输入监测点编号!", vbOKOnly + vbExclamation, "警告"
Exit Sub
Text1.SetFocus
Else
Set rs = ExcSQL("select * from 2010年6月水质监测成果")
While (rs.EOF = False)
If Trim(rs.Fields(0)) = Trim(Text1.Text) Then
MsgBox "此监测点已存在,请重新输入!", vbOKOnly + vbExclamation, "警告"
Text1.SetFocus
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
Text5.Text = ""
Text6.Text = ""
Text7.Text = ""
Text8.Text = ""
Text10.Text = ""
Text11.Text = ""
Text12.Text = ""
Text13.Text = ""
Text14.Text = ""
Text15.Text = ""
Text16.Text = ""
Text17.Text = ""
Text18.Text = ""
Text19.Text = ""
Exit Sub
Else
rs.AddNew
rs.Fields(0) = Trim(Text1.Text)
rs.Fields(1) = Trim(Text2.Text)
rs.Fields(2) = Trim(Text3.Text)
rs.Fields(3) = Trim(Text4.Text)
rs.Fields(4) = Trim(Text5.Text)
rs.Fields(5) = Trim(Text6.Text)
rs.Fields(6) = Trim(Text7.Text)
rs.Fields(7) = Trim(Text8.Text)
rs.Fields(8) = Trim(Text10.Text)
rs.Fields(9) = Trim(Text11.Text)
rs.Fields(10) = Trim(Text12.Text)
rs.Fields(11) = Trim(Text13.Text)
rs.Fields(12) = Trim(Text14.Text)
rs.Fields(13) = Trim(Text15.Text)
rs.Fields(14) = Trim(Text16.Text)
rs.Fields(15) = Trim(Text17.Text)
rs.Fields(16) = Trim(Text18.Text)
rs.Fields(17) = Trim(Text19.Text)
rs.MoveNext
rs.Close
Me.Hide
MsgBox "添加成功!", vbOKOnly + vbExclamation, "添加"
End If
Wend
End If
End Sub 展开
3个回答
展开全部
没有连接到数据库,当然不能操作
'建立连接对象
dim cnn as new adodb.connection
'连接到数据库,对象cnn 的data source 属性没有设置,根据你的数据库位置及名称自己设置
cnn.connectionstring="provider=microsoft.jet.oledb.4.0;data source="
cnn.open
set rs.activeconnection =cnn
操作完数据库后关闭数据库
cnn.close
'建立连接对象
dim cnn as new adodb.connection
'连接到数据库,对象cnn 的data source 属性没有设置,根据你的数据库位置及名称自己设置
cnn.connectionstring="provider=microsoft.jet.oledb.4.0;data source="
cnn.open
set rs.activeconnection =cnn
操作完数据库后关闭数据库
cnn.close
追问
我在模块里有连接的数据库,问题是同样的代码在别人机器上没问题,到我这运行就出错
展开全部
ExcSQL 方法的问题 应该是数据库连接没有成功open
追问
那么请问要怎么解决呢?
追答
debug 看是什么原因了 比如用户密码错误
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
..... Me.hide .....
text 控件为什么不用数组
text 控件为什么不用数组
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询