Construci '....LIKE.....' Error !!!!

franzxx

New member
Local time
Today, 06:34
Joined
Aug 8, 2005
Messages
7
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.
 
Presuming that's ADO as it appears, substitute % for * in the criteria.
 
Don't work also with % !!!!!
Why????
 
Post all the code or a sample db.
 
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.
 
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?
 
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.
 
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)
 

Users who are viewing this thread

Back
Top Bottom