尝试创建用户名/密码验证表单。当我单击登录按钮即 comamand1_click() 时,出现以下错误“对象变量或未设置块变量”。当我点击调试它指向
> rs.ActiveConnection = conn
我输入的代码:
Dim a
Dim conn As ADODB.Connection
Dim rs As ADODB.Recordset
Private Sub Command1_Click()
Set conn = New ADODB.Connection
conn.ConnectionString = "Provider = Microsoft.ACE.OLEDB.12.0; Data Source = C:\VB Project\logindetails1.mdb"
conn.Open
If conn = Null Then
MsgBox ("no db")
End
End If
rs.ActiveConnection = conn
rs.Source = "select * from login"
rs.Open
rs.MoveFirst
While Not rs.EOF
If Text1.Text = rs.Fields("id") And Text2.Text = rs.Fields("password") Then
a = 1
Else
a = 0
End If
Wend
rs.Close
conn.Close
Set rs = Nothing
Set conn = Nothing
If a = 1 Then
MsgBox ("Login Successful!!")
Else
MsgBox ("Invalid Details!!")
End If
End Sub
Private Sub Command2_Click()
Text1.Text = ""
Text2.Text = ""
End Sub
Private Sub Command3_Click()
End
End Sub