求助,登录窗体连接 Access 是数据库错误
哪位大神帮帮忙 一运行就出现实时错误
from 子句语法错误
然后显示 rst0.Open Trim$(SQL), cnn, adOpenKeyset, adLockOptimistic 这句话错误
登录界面程序如下
模块代码
Public usertype As String
Public username As String
Public gst As String
Public Function ConnectString() As String
ConnectString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=House.mdb;Persist Security Info=False"
End Function
Public Function executeSQL(ByVal SQL As String) As ADODB.Recordset
Dim cnn As ADODB.Connection
Dim rst0 As ADODB.Recordset
Set cnn = New ADODB.Connection
cnn.Open ConnectString
Set rst0 = New ADODB.Recordset
rst0.Open Trim$(SQL), cnn, adOpenKeyset, adLockOptimistic
Set executeSQL = rst0
End Function
Public Function testtxt(txt As String) As Boolean
If Trim(txt) = "" Then
testtxt = False
Else
testtxt = True
End If
End Function
Dim miCount As Integer
Private Sub cmdcancel_click()
Me.Hide
End
End Sub
窗体代码如下
Private Sub cmdok_click()
Dim i As Integer
Dim SQL As String
Dim rst As ADODB.Recordset
If Comb.Text = "" Then
MsgBox "请选择用户类型!", vbOKOnly + vbExclamation, "警告"
Comb.SetFocus
Exit Sub
End If
If txtname.Text = "" Then
MsgBox "请重新输入用户名!", vbOKOnly + vbExclamation, "警告"
txtname.SetFocus
txtname.Text = ""
Exit Sub
End If
Select Case Comb.Text
Case "系统管理员"
usertype = "0"
Case "普通用户"
usertype = "1"
End Select
If txtpwd.Text = "" Then
MsgBox "请重输入用户密码!", vbOKOnly + vbExclamation, "警告"
txtpwd.SetFocus
Exit Sub
End If
SQL = "select * from user where user_name = '" & txtname.Text & "'"
Set rst = executeSQL(SQL)
If rst.EOF Then
MsgBox "没有这个用户,请重新输入用户名!", vbOKOnly + vbExclamation, "警告"
txtname.SetFocus
txtname.Text = ""
txtpwd.Text = ""
Exit Sub
End If
If rst.Fields(2) <> usertype Then
MsgBox "用户名与用户类型不匹配!", vbOKOnly + vbExclamation, "警告"
txtname.Text = ""
txtpwd.Text = ""
Exit Sub
End If
If Trim(rst.Fields(1)) = Trim(txtpwd.Text) Then
username = Trim(txtname.Text)
rst.Close
main.Show
Unload Me
Else
MsgBox "输入密码不正确,请重新输入!", vbOKOnly + vbExclamation, "警告"
txtpwd.SetFocus
txtpwd.Text = ""
miCount = miCount + 1
If miCount = 3 Then
Me.Hide
Exit Sub
End If
End If
End Sub
Private Sub Form_Load()
miCount = 0
Comb.AddItem "系统管理员"
Comb.AddItem "普通用户"
Me.Left = (Screen.Width - Me.Width) / 2
Me.Top = (Screen.Height - Me.Height) / 2
End Sub