Solved

Filter Query using Access

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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to debug this code 7 65
SLMGR Switches Are Not Working On KMS Host 3 166
which modules are active in VB6 project? 6 56
add criteria to query in VB, Access 2003 2 47
I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

740 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