Solved

Filter Query using Access

Posted on 2002-05-15
3
128 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 50 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

705 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