Reputation: 125
Trying to create a username/password validation form. getting the the following error "Object variable or with block variable not set" when i click login button i.e comamand1_click(). when i click debug it points to
> rs.ActiveConnection = conn
The code that i typed:
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
Upvotes: 0
Views: 3730
Reputation: 17584
I think your rs (ADODB.Recordset
) variable is Nothing
.
You need to create the object.
Set rs = New ADODB.Recordset
Also, I think you'll need to use the Set
keyword when setting the recordset's connection:
Set rs.ActiveConnection = conn
Upvotes: 6