?
Solved

Filter Query using Access

Posted on 2002-05-15
3
Medium Priority
?
129 Views
Last Modified: 2010-05-02
Hello Experts:

Im trying to create a function that will perform a search on a specified table and column from an Access Database.  Here is the function I have written:

Function FindString(TableName As String, ColumnName As String, Criteria As String) As Variant
Dim Rst As New ADODB.Recordset
Dim SetConn As ADODB.Connection

Set SetConn = New ADODB.Connection

With SetConn
    .ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\website2\wsdb\Discuss.mdb;Persist Security Info=False;User ID=admin;"
    .Open SetConnString
End With

With Rst
    SqlString = "Select * From " + TableName + " Where " + ColumnName + " Like '" & Criteria & "'"
    .Open SqlString, SetConn, adOpenStatic, adLockOptimistic, adCmdText
    If Not .BOF Then
        FindString = .GetRows
    End If
End With

Rst.Close
SetConn.Close

Set Rst = Nothing
Set SetConn = Nothing

End Function

This function should produce a querystring something similiar to "Select * from TableName Where Column Like *Criteria*"

But, it doesn't seem to be working as it never returns the variant array.

Any help would be nice

VB6, Access 2000
0
Comment
Question by:escheider
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 75

Accepted Solution

by:
Anthony Perkins earned 200 total points
ID: 7012657
Instead of:
"Select * from TableName Where Column Like *Criteria*"

Use:
"Select * from TableName Where Column Like %Criteria%"

Anthony

0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 7012659
Also, you may get better performance if you change the following line:
.Open SqlString, SetConn, adOpenStatic, adLockOptimistic, adCmdText

To:
.Open SqlString, SetConn, adOpenForwardOnly, adReadOnly, adCmdText
0
 
LVL 4

Author Comment

by:escheider
ID: 7012669
Thanks ac, I figured it was something simple.  Also, thanks for performance tips.  It actually works...yipee
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month9 days, 18 hours left to enroll

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question