PDA

Click to See Complete Forum and Search --> : Query works in Access 2k but not in VB6


Sep 12th, 2000, 09:46 AM
Urrrgh!!! Am soooo annoyed! OK...figure this one out if you can...

I've got an Access 2000 database called "Phone Book.mdb" in the same directory as my program.

The database contains a table called "People" with the fields "ID", "Name" and "Notes".

There is currently 1 record in the table:

ID Name Notes
1 Matthew Ralston

If I run the following query SELECT ID, Name FROM People WHERE Name LIKE 'm*' in Access it works fine and returns 1 record. However if I run it in VB using ADO 2.1 it returns 0 records:

Dim oConn As New ADODB.Connection, oRS As New ADODB.Recordset

oConn.ConnectionString = "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=Phone Book.mdb"
oConn.Open

oRS.Open "SELECT ID, Name FROM People WHERE Name LIKE '" & "m" & "*'", oConn
oRS.MoveFirst

Debug.Print oRS("Name")

oRS.Close
oConn.Close

Note that this is a simplified version of the code...the real one runs inside a loop and puts all records returned into a treeview control. I have tested the above code and the same problem occurs.

Any ideas why?

[Edited by matthewralston on 09-12-2000 at 10:48 AM]

AKA
Sep 12th, 2000, 10:39 AM
ADO uses

SELECT ID, Name FROM People WHERE Name LIKE 'm%'

and DAO uses

SELECT ID, Name FROM People WHERE Name LIKE 'm*'


See the diffrence, % for ADO and * for DAO

Sep 12th, 2000, 10:46 AM
Ooooh!!!!! My hero!!!! Thank you! Thank you! Thank you!


Geez how idiotic is that?
Am gonna shoot Bill G when I see him next!!!


Well...at least it works now! Ta. It was drivin me up the wall. :)