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 展开
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 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询