Office中国论坛/Access中国论坛
标题:
帮我看看错在那里了?
[打印本页]
作者:
gxy1000
时间:
2011-2-26 18:11
标题:
帮我看看错在那里了?
本帖最后由 gxy1000 于 2011-2-26 18:17 编辑
Private Sub Command7_Click()
'定义 connection 对象
Dim cn As ADODB.Connection
'定义 recordset 对象
Dim rs As New ADODB.Recordset
Dim username As String
Dim userpass As String
Dim sql As String
'使用access内置 connection对象
Set cn = CurrentProject.Connection
Text1.SetFocus
username = Text1.Text
Text3.SetFocus
username = Text3.Text
sql = "select*from users_1 where username =""& username &" 'and
Password = "'& userpass & '"""
rs.Open sql, cn
If rs.EOF Then
MsgBox "登录失败"
Text1.SetFocus
Text1.Text = ""
Text3.SetFocus
Text3.Text = ""
Else
DoCmd.Close
DoCmd.OpenForm "主界面"
MsgBox "登录成功"
End If
'关闭 recodset 对象和connection对象并释放内存资源
rs.Close
cn.Close
Set rs = Nothing
End Sub
复制代码
作者:
roych
时间:
2011-2-27 11:46
代码不是LZ自己写的吧(恕俺恶毒地这样想一下,(*^__^*) 嘻嘻……),代码贴过来时要顺手把相应的变量改过来的呀。这是我修改后的代码,请对比和你的不同之处。
Private Sub Command7_Click()
'定义 connection 对象
Dim cn As ADODB.Connection
'定义 recordset 对象
Dim rs As New ADODB.Recordset
Dim username As String
Dim userpass As String
Dim sql As String
'使用access内置 connection对象
Set cn = CurrentProject.Connection
Text1.SetFocus
username = Text1.Text
Text3.SetFocus
userpass = Text3.Text
sql = "select*from 用户表 where 用户名 ='" & username & " 'and 密码 = '" & userpass & "'"
rs.Open sql, cn
If rs.EOF Then
MsgBox "登录失败"
Text1.SetFocus
Text1.Text = ""
Text3.SetFocus
Text3.Text = ""
Else
DoCmd.Close
DoCmd.OpenForm "主界面"
MsgBox "登录成功"
End If
'关闭 recodset 对象和connection对象并释放内存资源
rs.Close
cn.Close
Set rs = Nothing
End Sub
复制代码
[attach]44941[/attach]
作者:
gxy1000
时间:
2011-2-27 14:40
回复
roych
的帖子
我试试看!
欢迎光临 Office中国论坛/Access中国论坛 (http://www.office-cn.net/)
Powered by Discuz! X3.3