Please help me on my project. I used this for my log in form. The registration form worked well and its easy for me. There are many errors almost 3. The errors are on the first 3 statements.

line 1: syntax error (missing operator) in query expression 'ID Number = '[what i type]''.
line 2: method 'refresh' of object 'iadodc' failed
line 3: object variable or with block variable not set

Private Sub Command1_Click()

Adodc1.RecordSource = ("select * from Student where ID Number ='" & Text1.Text & "'") '<=== line 1
Adodc1.Refresh    '<=== line 2
If (Adodc1.Recordset.EOF = False) Then    '<=== line 3
    If Adodc1.Recordset.Fields("Password") = Text2.Text Then
    MsgBox ("Successfully Logged-in"), vbInformation, "Log-in"
    Homepage.Label1.Caption = Text1.Text
    Homepage.Label2.Visible = True
    Login.Visible = False
    Homepage.Visible = True
    Else
    Val (X) + 1
    MsgBox ("Wrong Log-in information"), vbInformation + vbRetryCancel, "Log-in"
    End If
Else
    Val (X) + 1
    MsgBox ("Wrong Log-in information"), vbInformation + vbRetryCancel, "Log-in"
End If

If X = 3 Then
MsgBox ("Maximum Log-in Reached!"), vbCritical + vbOKOnly, "Log-in"
End If
End Sub

Private Sub Command2_Click()
answer = MsgBox("Do you want to cancel?", vbExclamation + vbYesNo, "Confirm")
If answer = vbYes Then
End
Else
MsgBox "Action canceled", vbInformation, "Confirm"
End If
End Sub

Private Sub Form_Load()
Dim X As Integer
X = 0
End Sub

Recommended Answers

All 3 Replies

1. Please read our forum rules :D
2. ID Number field includes space, so you should enclosed it with square brackets so it can be identified by your query as a whole field.
3. Adodc1.Refresh and Adodc1.Recordset.EOF will be fix when you fix the first error.

Private Sub Command1_Click()

Adodc1.RecordSource = ("select * from Student where [ID Number] ='" & Text1.Text & "'") 
Adodc1.Refresh 
If (Adodc1.Recordset.EOF = False) Then  
    If Adodc1.Recordset.Fields("Password") = Text2.Text Then
    MsgBox ("Successfully Logged-in"), vbInformation, "Log-in"
    Homepage.Label1.Caption = Text1.Text
    Homepage.Label2.Visible = True
    Login.Visible = False
    Homepage.Visible = True
    Else
    Val (X) + 1
    MsgBox ("Wrong Log-in information"), vbInformation + vbRetryCancel, "Log-in"
    End If
Else
    Val (X) + 1
    MsgBox ("Wrong Log-in information"), vbInformation + vbRetryCancel, "Log-in"
End If

Also, avoid using field name with spaces to prevent this kind of error. Name it like this ID_Number instead of using spaces on it.

Mark the thread as solve if this solves your problem :)

1. Please read our forum rules :D
2. ID Number field includes space, so you should enclosed it with square brackets so it can be identified by your query as a whole field.
3. Adodc1.Refresh and Adodc1.Recordset.EOF will be fix when you fix the first error.

Private Sub Command1_Click()

Adodc1.RecordSource = ("select * from Student where [ID Number] ='" & Text1.Text & "'") 
Adodc1.Refresh 
If (Adodc1.Recordset.EOF = False) Then  
    If Adodc1.Recordset.Fields("Password") = Text2.Text Then
    MsgBox ("Successfully Logged-in"), vbInformation, "Log-in"
    Homepage.Label1.Caption = Text1.Text
    Homepage.Label2.Visible = True
    Login.Visible = False
    Homepage.Visible = True
    Else
    Val (X) + 1
    MsgBox ("Wrong Log-in information"), vbInformation + vbRetryCancel, "Log-in"
    End If
Else
    Val (X) + 1
    MsgBox ("Wrong Log-in information"), vbInformation + vbRetryCancel, "Log-in"
End If

Also, avoid using field name with spaces to prevent this kind of error. Name it like this ID_Number instead of using spaces on it.

Mark the thread as solve if this solves your problem :)

Thank YOU! It worked like charm and your right the first line solves it all.

Your welcome! :D And Remember to mark your thread as Solved when your question is answered.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.