Option Explicit‘这是公共模块
Public adocon As ADODB.Connection
Public adminp As Boolean
Public readp As Boolean
Public username As String
Public Function executesql(ByVal sql As String) As ADODB.Recordset
Dim rst As ADODB.Recordset
Set adocon = New ADODB.Connection
adocon.CursorLocation = adUseClient
adocon.ConnectionString = Connstring
adocon.Open
Dim stokens() As String
On Error GoTo executesql_error
stokens = Split(sql, " ")
If InStr("inser,delete,update", UCase(stokens(0))) Then
adocon.Execute sql
Else
Set rst = New ADODB.Recordset
rst.Open Trim(sql), adocon, adOpenKeyset, adLockOptimistic
Set executesql = rst
End If
executesql_exit:
Set rst = Nothing
Set adocon = Nothing
Exit Function
executesql_error:
Resume executesql_exit
End Function
Public Function Connstring() As String
Connstring = "provider = microsoft.Jet.OLEDB.4.0;Data source =" & App.Path & "\123.mdb "
End Function
Public Function executeqx() As Boolean
Dim sql As String
Dim rst As ADODB.Recordset
Set adocon = New ADODB.Connection
adocon.ConnectionString = Connstring
adocon.Open
Set rst = New ADODB.Recordset
sql = "select * from use where username='" & username & "'"
rst.Open Trim(sql), adocon, adOpenKeyset, adLockOptimistic
If rst.EOF = True Then
MsgBox "非法用户", vbExclamation + vbOKOnly, "警告"
executeqx = Null
Exit Function
End If
If rst.Fields("admin") Then
executeqx = True
Exit Function
ElseIf rst.Fields("readonly") Then
executeqx = False
End If
rst.Close
On Error GoTo executesql_error
executesql_exit:
Set rst = Nothing
Set adocon = Nothing
Exit Function
executesql_error:
Resume exectuesql_exit
End Function
’这是登录窗体代码
Private Sub Command1_Click()
Dim txtsql As String
Dim mrc As New ADODB.Recordset
txtsql = "select username from use where username=" & Trim(Text1.Text) & ""
Set mrc = executesql(txtsql)
If mrc.EOF = True Then
MsgBox "用户名错误!", vbExclamation + vbOKOnly, "警告"
Text1.SetFocus
Text1.SelStart = 0
Text1.SelLength = Len(Text1.Text)
Exit Sub
End If
username = mrc.Fields(0)
txtsql = "select username from use where password=" & Trim(Text2.Text) & ""
Set mrc = executesql(txtsql)
If mrc.EOF = True Then
MsgBox "密码错误!", vbExclamation + vbOKOnly, "警告"
Text2.SetFocus
Text2.SelStart = 0
Text2.SelLength = Len(Text1.Text)
Exit Sub
End If
If executeqx Then
adminp = True
Else
readp = True
End If
End Sub
Private Sub Command2_Click()
end
End Sub
运行时出现了“对象关闭时不允许操作”实时错误3704,请问大家怎么改呢?