invalid use of property

Dim search As String
        search = Trim(txtSearch.Text)
    Select Case cmbSearch
        Case "By: Customer Name": Call DataGrid("select * from list1 where CustomerName like '" & search & "%'")
        Case "By: Date": Call DataGrid("select * from list1 where Date like '" & search & "%'")
        Case "By: Event": Call DataGrid("select * from list1 where Event like '" & search & "%'")
        Case "By: Comment": Call DataGrid("select * from list1 where Comment like '" & search & "%'")
    End Select

DATAGRID
ADODC
MYSQL
database: database1
table: list1

Recommended Answers

All 23 Replies

Suggestion:--
1. Instead of using Case cmbSearch
Case "By: Customer Name":

take the value from a combobox instead (use the index in CASE not the text).

2. Don't use like operator on a Date field, you will get unexpected result.

Q. What is that DataGrid in your code, is that simply a control or a method name ?

what do you mean? example code pls

Suggestion:--
1. Instead of using Case cmbSearch
Case "By: Customer Name":

take the value from a combobox instead (use the index in CASE not the text).

Select Case cmbSearch.ListIndex

Case Is = 0
'Code here
Case Is = 1
'Code Here
End Select

2. Don't use like operator on a Date field, you will get unexpected result.

Call DataGrid("select * from list1 WHERE Date = DateValue('" & search & "'")

Q. What is that DataGrid in your code, is that simply a control or a method name ?

It is a sub calling accordingly...

DataGrid is the name of my DataGrid

look at the attachment i want those kind of search in my project :) help pls

Is this your code ?

Do you understand the code in this project ?

that is not my i just downloaded it for my reference

it's not working :(

help pls

Cry loud.

No one is going to care for you till you show some effort, and that has already been communicated to you.

i dont have any clue where to start i am done searching it's not working for me..tsk

Ohh...

You even didn't start as of yet..

I had a look at the attached file. The user was using a Listview control and NOT a datagrid, that is why your code did not work as was the intention. Change your datagrid to a listview if you want it to work the same as the attached code.

error :(

If Adodc.Recordset.RecordCount > 0 Then Adodc.Recordset.MoveFirst
Adodc.RecordSource = "details where upper(CustomerName) like '%" & UCase(Trim(txtSearch.Text)) & "%'"
Adodc.Refresh
Adodc.RecordSource = "details where upper(CustomerName) like '" & UCase(Trim(txtSearch.Text)) & "%'"

Remove the first "%" sign.

it's still the same
when i click debug this one will get yellow

Adodc.Refresh

did u figure out my module?

As far as the module goes, I've tested it and it was working fine on my side. Post all the code in your module, I think you are calling the same connection twice, hence the error.

Your problem above, adodc is a reserved name, you can not name a function with that name, unless it is a data control and not code...

i change adodc to adodc1 and it's still have an error

I will have to see a screen capture of your design form and the code. I still say that Adodc is a data control...

If Adodc1.Recordset.RecordCount > 0 Then Adodc1.Recordset.MoveFirst
Adodc1.RecordSource = "details where upper(CustomerName) like '" & UCase(Trim(txtSearch.Text)) & "%'"
Adodc1.Refresh
conn.Close

See, I told you that adodc is a data control, hence the error. You need to search your form for it and make sure that the connection is set properly, then set the recordsource -

Adodc.RecordSource = "SELECT * FROM details WHERE CustomerName like '" & UCase(Trim(txtSearch.Text)) & "%'"

You tend to copy other sample code from the web, which in it self is good, but you do not understand the code at all. You then try and use the code as it was downloaded and expect it to work, ouch...;)

commented: it worked ^^ +1

not working
and doesn't have any error

my code in combobox

Select Case cmbSearch.ListIndex

Case Is = 0
Adodc1.RecordSource = "SELECT * FROM details WHERE CustomerName like '" & UCase(Trim(txtSearch.Text)) & "%'"
End Select

On which event this code is being called ?

You do not need the trim functions etc. The search by wild character "%" looks for anything similar to the name

Adodc1.RecordSource = "SELECT * FROM details WHERE CustomerName like '" & txtSearch.Text & "%'"

I suggest you read up more on the control at this link. I still don't know why you are using the control though.

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.