vb程序报错:对象打开时不允许操作 具体情况是这个窗体打开一次是可以的,但关闭后再次打开就会报这个错误

如果将整个程序关闭又能打开一次DimblnaddAsBooleanDimcnAsNewADODB.ConnectionDimrsAsNewADODB.RecordsetP... 如果将整个程序关闭又能打开一次

Dim blnadd As Boolean
Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset

Private Sub Command1_Click()
Dim SQL1 As String

If Len(Text3.Text) = 0 Or Len(Text9.Text) = 0 Then

MsgBox "数据不全请重新输入", vbInformation, "提示"
Else

rs.Open "select * from jbxx where 行号='" + Text1.Text + "'", cn, adOpenKeyset, adLockOptimistic
If rs.RecordCount > 0 Then '如果记录大于零,则修改该记录
With rs
.Fields("行号") = Text1.Text: .Fields("条码") = Text2.Text
.Fields("品名") = Text3.Text: .Fields("其它名称") = Text4.Text
.Fields("拼音码") = Text5.Text: .Fields("品类") = Text6.Text
.Fields("零售价") = Text7.Text: .Fields("会员价") = Text8.Text
.Fields("成本价") = Text9.Text: .Fields("利润") = Text10.Text
.Fields("利润率") = Text11.Text
.Update
End With
End If
rs.Close

QK
MsgBox "修改成功", vbInformation, "提示"
Text1.SetFocus
End If
End Sub

Private Sub Form_Load()
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\cggl.mdb;Persist Security Info=False"
KeyPreview = True
End Sub
Private Sub QK()

Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
Text5.Text = ""
Text6.Text = ""
Text7.Text = ""
Text8.Text = ""
Text9.Text = ""
Text10.Text = ""
Text11.Text = ""

End Sub
Private Sub Command2_Click()
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
Text5.Text = ""
Text6.Text = ""
Text7.Text = ""
Text8.Text = ""
Text9.Text = ""
Text10.Text = ""
Text11.Text = ""
End Sub

Private Sub Command3_Click()

Unload Me
展开
 我来答
chinaboyzyq
2012-04-10 · TA获得超过1.3万个赞
知道大有可为答主
回答量:1.3万
采纳率:89%
帮助的人:3249万
展开全部
Private Sub Form_Unload(Cancel As Integer)
cn.close
rs.close
End Sub
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式