Solved

Filter Query using Access

Posted on 2002-05-15
3
123 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
  • 2
3 Comments
 
LVL 75

Accepted Solution

by:
Anthony Perkins earned 50 total points
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks ac, I figured it was something simple.  Also, thanks for performance tips.  It actually works...yipee
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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…

743 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now