franzxx
08-12-2005, 09:34 AM
I have a button with this code :
Private Sub button_Click()
..................
recordeset.open "SELECT * FROM tableuser WHERE username LIKE 'a*'"
...............
end Sub
Why the construct LIKE don'work ???
If I write the same string into a Query she work!!!!!!!
Why the correct query don't work if inserted into Visual Basic code (button_Click) ???????
Thank you.
pbaldy
08-12-2005, 10:00 AM
Presuming that's ADO as it appears, substitute % for * in the criteria.
franzxx
08-12-2005, 10:08 AM
Don't work also with % !!!!!
Why????
pbaldy
08-12-2005, 10:10 AM
Post all the code or a sample db.
franzxx
08-12-2005, 10:18 AM
the source code is this:
Private Sub cmdcerca_Click()
Dim rstclienti As ADODB.Recordset
Set rstclienti = New ADODB.Recordset
rstclienti.Open "SELECT * FROM clienti WHERE ragsociale LIKE 'A%'", CurrentProject.Connection, adOpenKeyset, adLockReadOnly
If rstclienti.RecordCount > 0 Then
rstclienti.MoveFirst
x = visualizzadati()
End If
Exit Sub
Thank you.
pbaldy
08-12-2005, 10:39 AM
I don't know what this is supposed to do:
x = visualizzadati()
but the rest is fine. I just copied it into a test db, changed the table and field names, and it worked fine. What error do you get?
franzxx
08-12-2005, 11:13 AM
visualizzadati() is a function that write into varius textboxes values of the current record pointed by rstclienti.....
Any error occour, simply the recordset rstclienti is empty....
If I write the same query into ACCESS QUERY she work (substituing % with *).
i think that the problem is using the construct LIKE with Visual Basic 6.
PS:I'm italian and i'm sorry for my english not correct, i hope to be clear about my problem.
pbaldy
08-12-2005, 11:45 AM
Your English is better than my Italian! Like I said, I tested that and it works fine in Access VBA. I don't have time to set up a test in VB6. I've used DAO to connect to Access db's from VB6, and I had to specify the mdb. Have you done that? I'm not too good with ADO, so I don't know if CurrentProject.Connection is enough from VB6. I used this for DAO:
Set dbAccess = Workspaces(0).OpenDatabase(PathToDBHere)
Set rsAccess = dbAccess.OpenRecordset("SELECT...", dbOpenDynaset)