SQL Recordset criteria with a *

G

Guest

Below is my code. I have a form that has a field named [Criteria] and a
button that when clicked creates a new recordset and sets the form to use the
recordset:

Dim rsCodes As ADODB.Recordset
Set rsCodes = New ADODB.Recordset
sSQL = "SELECT * FROM tabCodeIncidentType Where [Description] Like
'Fire*'"
rsCodes.Open sSQL, CurrentProject.Connection, adOpenKeyset,
adLockOptimistic

Set Forms("frmLookupCodes").Recordset = rsCodes

When I click the button to run this code, all of the records on the form go
away (I originally opened the form without any criteria and displayed all the
records. I am wondering what is wrong with my code. If I remove the * after
'Fire, then it does bring up a record that contains only the word Fire in the
description field. However, that goes away when the * is put in.

Any help?
 
D

Douglas J. Steele

* (and ?) only work as wildcard characters with DAO. ADO uses % and _ as
wildcard characters.
 
G

Guest

Great - Thanks a lot.

Douglas J. Steele said:
* (and ?) only work as wildcard characters with DAO. ADO uses % and _ as
wildcard characters.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Hindsey said:
Below is my code. I have a form that has a field named [Criteria] and a
button that when clicked creates a new recordset and sets the form to use the
recordset:

Dim rsCodes As ADODB.Recordset
Set rsCodes = New ADODB.Recordset
sSQL = "SELECT * FROM tabCodeIncidentType Where [Description] Like
'Fire*'"
rsCodes.Open sSQL, CurrentProject.Connection, adOpenKeyset,
adLockOptimistic

Set Forms("frmLookupCodes").Recordset = rsCodes

When I click the button to run this code, all of the records on the form go
away (I originally opened the form without any criteria and displayed all the
records. I am wondering what is wrong with my code. If I remove the * after
'Fire, then it does bring up a record that contains only the word Fire in the
description field. However, that goes away when the * is put in.

Any help?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top