HI EVERYONE CAN SOMMEONE HELP ME PLEASE I'M STRUGGLING WITH THIS CODE TO SEARCH THROUGH MY DATABASE IN ACCESS BUT WHEN I TRY TO RUN IT DISPLAY A MESSAGE "OBJECT REQUIRED " WHAT CAN I DO?

Private Sub cmdSearch_Click()
Dim Searchit As String, Founder As Boolean
Searchit = UCase(InputBox("Enter Item code:"))
If Len(Searchit) > 0 Then
Adodc1.Recordset.MoveFirst
Founded = False
End If
Do While (Not Founder) And (Not Adodc1.Recordset.EOF)
If UCase(Adodc1.Recordset.Fields("ITEM_CODE")).Value = Searchit Then
Founder = True
Else
Adodc1.Recordset.MoveNext
End If
Loop
If Not Founder Then
MsgBox "Unable to find the required item", , "Not Found"
Adodc1.Recordset.MoveLast
Else
MsgBox "Must enter an item code", , ""
End If

Please connect your Adodc1 to the database and table first and then run this query

any code u use for find? what that?

sorry but i didn't get your response.

what code u use for find.

Please connect your Adodc1 to the database and table first and then run this query

Yeah my database is already linked to the ADODC. Sorry Abu but that the code you see that im using

Do this

Private Sub cmdSearch_Click()
Dim Searchit As String, Founder As Boolean
Searchit = UCase(InputBox("Enter Item code:"))
If Len(Searchit) > 0 Then
'add this line
Adodc1.Refresh
Adodc1.Recordset.MoveFirst
Founded = False
End If
Do While (Not Founder) And (Not Adodc1.Recordset.EOF)
'u can add UCASE i just removed it for my query
If Adodc1.Recordset.Fields("item_code").Value = Searchit Then
Founder = True
'do something here because your query has matched. The loop is running aimless. do like this
MsgBox "You have queried for item code " & Searchit & " which belongs to " & Adodc1.Recordset.Fields(1)
'and exit procedure
Exit Sub
End If
Loop

If Not Founder Then
MsgBox "Unable to find the required item", , "Not Found"
Adodc1.Recordset.MoveLast
Else
MsgBox "Must enter an item code", , ""
End If
End Sub

I am uploading a sample project for ur reference.

Also make sure that u have selected the CommandType property of the ADODC object.
I have selected it as 2 - adCmdTable.

1. Right click on the ADODC object and open ADODC Properties.
2. In the RecordSource tab select the required command type.
3. And Table or stored procedure name if the RecordSource is "2 - adCmdTable" or "4 - adCmdStoredProc"
or
write the Command Text (SQL) if the RecordSource is "8 - adCmdUnknown" or "1 - adCmdText"


hope this solves ur problem


Regards
Shaik Akthar

Thanks for your solution but i've done all that but it still telling me "object variable or block variable not defineed".

u tried to download & execute my sample project?

Thanks i tried this coding it is running but it only shows for the first record i want it to be able to show the info of any item in the dbase source. thanks

Do this

Private Sub cmdSearch_Click()
Dim Searchit As String, Founder As Boolean
Searchit = UCase(InputBox("Enter Item code:"))
If Len(Searchit) > 0 Then
'add this line
Adodc1.Refresh
Adodc1.Recordset.MoveFirst
Founded = False
End If
Do While (Not Founder) And (Not Adodc1.Recordset.EOF)
'u can add UCASE i just removed it for my query
If Adodc1.Recordset.Fields("item_code").Value = Searchit Then
Founder = True
'do something here because your query has matched. The loop is running aimless. do like this
MsgBox "You have queried for item code " & Searchit & " which belongs to " & Adodc1.Recordset.Fields(1)
'and exit procedure
Exit Sub
End If
Loop

If Not Founder Then
MsgBox "Unable to find the required item", , "Not Found"
Adodc1.Recordset.MoveLast
Else
MsgBox "Must enter an item code", , ""
End If
End Sub

USE

Adodc1.Recordset.MoveNext

BEFORE

Loop

STATEMENT

Regards
Shaik Akthar

It may be something like this.

Do While (Not Founder) And (Not Adodc1.Recordset.EOF)
 If Adodc1.Recordset.Fields("item_code").Value = Searchit Then
  Founder = True
  'do something here because your query has matched. The loop is running aimless. do like this
  MsgBox "You have queried for item code " & Searchit & " which belongs to " & Adodc1.Recordset.Fields(1)
  'and exit procedure
  Exit Sub
 End If
 [B]Adodc1.Recordset.MoveNext[/B]
Loop

Regards
Shaik Akthar

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.