在使用ADO控件调用创建的数据库时,总是出现编译错误。看了很多版本的解释,有的说不用设置ADO控件的属性,直接通过程序实现,有的说需要设置ADO属性,然后调用就行。我觉得两种方法应该都能实现,但不知道具体步骤,所以上论坛请教。帖上自己的东西。
代码:
Private Sub Command1_Click()
Dim db As Database
Dim rs As Recordset
Dim 账号 As String
Dim 密码 As String
Set db = OpenDatabase(App.Path & "\门禁系统.mdb")
Set rs = db.OpenRecordset("门禁系统\ID")
If Text1.Text <> "" Then
账号 = Text1.Text
密码 = Text2.Text
Do While Not rs.EOF
If 账号 = rs!账号 Then
If 密码 = rs!密码 Then
MsgBox "登陆成功", , "提示"
Exit Sub
Else
MsgBox "密码错误,请重新输入!", vbOKOnly, "提示"
Text2.Text = ""
Text2.SetFocus
Exit Sub
End If
Else
rs.MoveNext
End If
Loop
If rs.EOF Then
MsgBox "您的用户名不正确,请核实后输入!", vbOKOnly, "提示"
Text1.SetFocus
Text1.Text = ""
End If
Else
MsgBox "请输入您的用户名!", vbOKOnly, "提示"
Text1.SetFocus
End If
End Sub
Private Sub Command2_Click()
Unload Me
End Sub
Private Sub Timer1_Timer()
Randomize
Timer1.Enabled = False
i = Int(Rnd * 9999 + 0)
If Len(i) > 5 Or Len(i) < 4 Then
Timer1.Enabled = True
Call Timer1_Timer
Else
Label5.Caption = Int(i)
End If
End Sub