Solved

Changing the querry of ADO recordset

Posted on 2000-04-01
6
318 Views
Last Modified: 2013-11-23
Hi,
I have a small VB application with an access database as backend.  I amd using ADO connection.  It is working fine.  Now my requirement is very simple.  I have a text box in which if I type some thing, the records beginning with that should be displayed.  Initially I was using DAO and I was able to do this.  Now I'm trying to use ADO.  I don't know how to do this using ADO.  Basically I want to change the contents of the recordset at runtime depending upon a different querry.  Please help me in this with the command/syntax.

Thanks in advance,
Benny
0
Comment
Question by:bennyv
6 Comments
 
LVL 6

Expert Comment

by:Marine
ID: 2675933
"Select * from TableName where FieldName like '" & Text1.Text & "*'"
0
 
LVL 3

Expert Comment

by:altena
ID: 2675982
One way to do this is to create a new Recordset object when you need to re-query. (The old one will be destroyed by VB).

Another way is to use a parameterized query. Use the ADO.Command object. (This may not work correctly with older versions of access, so be carefull.)

Good Luck

0
 

Accepted Solution

by:
anand_m earned 50 total points
ID: 2676183
Try to display this using ADO recordset Find Method. Whenever you type a word,try to match for that word in the Recordset
0
VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

 
LVL 14

Expert Comment

by:wsh2
ID: 2676237
Benny:
Post your old code.. a picture is worth a thousand words.. <smile>.

altena:
you write: "One way to do this.. Another way.." How is this a definitive answer? Shame on you for locking this question down with an answer rather than allowing other comment.

The gyst of what the questioner is saying is "I don't know HOW to do this using ADO".. To that means.. your answer hardly suffices. By the way.. your parameterized ADO Command Object solution implies a Stored database procedure.. and I saw no mention of that anywhere in the question. To be honest, the questioner has not provided enough information.

Please remove your answer, so that Benny can benefit from other's comments.. and perhaps, benefit further by additional "comments" of your own making.. <smile>.
0
 

Author Comment

by:bennyv
ID: 2677416
I would like to accept the answer of anand m rather than altena's because altena didn't give me the code to use.  Anand's method was easy to use and I got the syntax from MSDN.  I tried Altena's answer also (by closing the current recordset and reopening it with the new query); but it did not work.  It is not displaying anything.  The absolute position is coming as -1.  But anand's method is working perfectly.  This is the code I used. :

Private Sub txtSearch_Change()
sqls = "NAMES LIKE " & "'" & txtSearch.Text & "*'"
adoPrimaryRS.MoveFirst
If txtSearch.Text <> "" Then
adoPrimaryRS.Find sqls
End If
End Sub

I would like to accept anand's answer.

Thanks altena.
Thanks to everybody for answering my question.

Benny
0
 

Author Comment

by:bennyv
ID: 2677422
One reason why I felt anand's answer is better is that, I feel it will be more efficient.  Because you are not reopening the record set.

Thanks anand
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…

810 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