源代码是这样的:无法执行到 msgbox"1" 这行,请问是何原因?
Private Sub Command4_Click()
Dim Rs As Object
Set Rs = CreateObject("adodb.recordset")
Rs.Open "Select * from user", CurrentProject.Connection, 1, 1
MsgBox "1"
Dim username As String
Dim userpass As String
Text0.SetFocus
username = Text0.Text
userpass = Text2.Text
If IsNull(username) Or IsNull(userpass) Then
MsgBox "用户名或密码不能为空,请重新输入!", vbOKOnly + vbInformation, "错误信息"
Else
If username <> Rs("username") Or userpass <> Rs("password") Then
MsgBox "用户名或密码不正确,请重新输入!", vbOKOnly + vbInformation, "错误信息"
Text0.SetFocus
Text0.Text = ""
Text2.SetFocus
Text2.Value = ""
Text0.SetFocus
Else
Rs.Close
Rs.Open "login_list", conn, adopendynamic, adlockoptimistic
Rs.AddNew
Rs!username = username
Rs!login = Now()
Rs!logout = CDate(0)
Rs.Update
Rs.Close
DoCmd.Close
DoCmd.OpenForm "main"
End If
End If
End Sub
Dim Rs As Object
Set Rs = CreateObject("adodb.recordset")
Rs.Open "Select * from user", CurrentProject.Connection, 1, 1
改成:
dim Rs as new ADODB.recordset
Rs.Open "Select * from user", CurrentProject.Connection, 1, 1
最初就是按照您的写法写的,同样不起作用,才改成像现在的写法的。
上传实例
点击下载此附件
实例以上传,请指教....
版主请现身~~~
2007版本以上,等版主解决了~~~
2003以上的不玩

总版主也不玩,那这个问题无解了吗?
问题当然并非无解,只要您有时间把它转换成2003版本的,去看的人可能会多些。
点击下载此附件
2003版本实例,请各位前辈指教,谢谢~
Rs.Open "Select * from [user]", CurrentProject.Connection, 1, 1
user为系统保留字,需要用[]括起来。
我都是用Dlookup来做的~~~觉得这样代码简单些。不知道老汉版主如何认为呢?罗衣试了下,还是有些问题,修改后如下:
Private Sub Command4_Click()
Dim Rs As New ADODB.Recordset
Dim cnn As New ADODB.Connection
Rs.Open "Select * from [user]", CurrentProject.Connection, 1, 1
Dim username As String
Dim userpass As String
Text0.SetFocus
username = Text0.Text
userpass = Text2.Value
If IsNull(username) Or IsNull(userpass) Then
MsgBox "用户名或密码不能为空,请重新输入!", vbOKOnly + vbInformation, "错误信息"
ElseIf username <> Rs("username") Or userpass <> Rs("password") Then
MsgBox "用户名或密码不正确,请重新输入!", vbOKOnly + vbInformation, "错误信息"
Text0.SetFocus
Text0.Text = ""
Text2.SetFocus
Text2.Value = ""
Text0.SetFocus
Else
Rs.Close
Rs.Open "login_list", CurrentProject.Connection, adOpenKeyset, adlockoptimistic
Rs.AddNew
Rs!username = username
Rs!login = Now()
Rs!logout = CDate(0)
Rs.Update
Rs.Close
DoCmd.Close
DoCmd.OpenForm "frm_test"
End If
End Sub
用Dcount比Dlookup可能更合适些,比如可写成:
dim n as long
dim ssql as string
dim strwh as string
strwh="username & userpass='" & nz(me.text0.value,"") & nz(me.text2.value,"") & "'"
n=dcount("*","[user]",strwh)
if n=0 then
MsgBox "用户名或密码错误!"
else
ssql="INSERT INTO login_list ( username,login,logout ) VALUES ("
ssql=ssql & me.Text0,value & ",#" & Now() & "#,#" & CDate(0) & "#)"
CurrentDb.Execute ssql
DoCmd.Close
DoCmd.OpenForm "frm_test"
end if
谢谢两位不吝指教,但是,两段代码我放进去执行后,还是无任何反应,问题依旧存在,请再给看看~!