帮忙看看这VB代码哪错了 帮忙改一下

来源:百度知道 编辑:UC知道 时间:2024/06/25 13:02:00
Option Explicit
Dim rst As New ADODB.Recordset
Dim con As New ADODB.Connection
Private Sub Command1_Click()
If (List1.ListCount = 1) Then
MsgBox "删除无效,系统必须有一个用户!", vbOKOnly + vbExclamation, "信息提示"
con.Close
Unload Me
Else
con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\gzgl.mdb;Persist Security Info=False"
con.CursorLocation = adUseClient
con.Open
Set rst = con.Execute("select * from 管理 where 用户名='" + Trim(List1) + "'and 密码='" + Trim(Text1) + "'")
If rst.EOF = True Then
MsgBox "密码错误,请重新输入密码!", vbOKOnly + vbExclamation, "警告"
Text1.SetFocus
Text1.Text = ""
Else
rst.Delete
rst.MoveNext
MsgBox "删除用户

1、Command1_Click()中
把 con.Close移到Form_Load() 中rst.Close
后面。

2、Command2_Click()

删除
rst.Close
con.Close


con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\gzgl.mdb;Persist Security Info=False"
con.CursorLocation = adUseClient
con.Open
这个代码全部写在form_load里面,按钮过程里面的全部删掉

否则你第一次点击按钮时打开一次,再次点击就会出现“对象打开时 不允许操作”

con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\gzgl.mdb;Persist Security Info=False"

中间的 双引号 应改为 单引号!!!!