大神,帮帮我吧《对象关闭时,不允许操作
这是自己做的一个连接数据库登录系统,以下代码都是从书上照敲的,程序访问一半就运行不了,大家能不能帮帮俺,俺是个菜鸟。在此谢谢
Dim x As Integer
Private Sub cmdlogin_Click()
Dim rst As New ADODB.Recordset
Dim stryhm As String
Dim strmm As String
Dim txtsql As String
Dim ok As String
stryhm = Trim(txtname)
strmm = Trim(txtpassword)
If txtname = "" Then
MsgBox "用户名不能为空!", vbCritical, "提示"
txtname.SetFocus
Exit Sub
Else
txtsql = "select * from 用户信息表 where 用户名='" & stryhm & "'"
Set rst = executesql(txtsql)
End If
If rst.EOF = True Then
MsgBox "没有这个用户,请重新输入用户名!", vbOKOnly + vbExclamation, "警告"
txtname = ""
txtname.SetFocus
ElseIf Trim(rst.Fields(1)) = Trim(txtpassword.Text) Then
ok = True
rst.Close
Me.Hide
tyhm = Trim(txtname.Text)
utype = rst.Fields(2)
MDIFmain.Show
End If
If txtpassword = "" Then
MsgBox "密码不能为空!", vbCritical, "登陆"
txtpassword.SetFocus
Exit Sub
End If
x = x + 1
If x < 3 Then
Unload Me
MDIFmain.Show
ElseIf x < 3 Then
MsgBox "输入有误,请重试", vbCritical, "登陆"
Else
MsgBox "输入三次有误,无权登陆本系统", vbCritical, "登陆"
End
End If
End Sub
Private Sub exit_Click()
If MsgBox("你选择了退出系统,是否退出?", vbYesNo + vbInformation, "登陆") = vbYes Then
End
Else
Exit Sub
End If
End Sub
Public Function connectstring() As String
connectstring = "provider=microsoft.jet.oledb.4.0;datasource=" & App.Path & "\database\shuju.mdb" & ";persist security info=false"
End Function
Public Function executesql(ByVal sql As String) As ADODB.Recordset
Dim cnn As ADODB.Connection
Dim rst As ADODB.Recordset
Dim stokens() As String
Dim msgstring As String
On Error GoTo executesql_error
stokens = Split(sql)
Set cnn = New ADODB.Connection
cnn.Open connectstring
If InStr("insert,delete,update", UCase$(stokens(0))) Then
cnn.executesql
msgstring = stokens(0) & "query successful"
Else
Set rst = New ADODB.Recordset
rst.CursorLocation = adUseClient
rst.Open Trim$(sql), cnn, adOpenKeyset, sdlockoptimistic
Set executesql = rst
End If
executesql_exit:
Set rst = Nothing
Set cnn = Nothing
Exit Function
executesql_error:
msgstring = "查询错误:" & Err.Description
Resume executesql_exit
End Function
------解决方案--------------------
在Set executesql = rst
这里下一个断点,看看rst是否为Nothing
你的连接字符串是否正确。
[解决办法]
你这问题会把版主气晕的
在代码某一行前面点一下,就是设置断点了,或者在菜单-调试中设置,程序运行到这一行就会停住,进入调试状态。
建议你还是好好看看书吧