Solved

Changing the querry of ADO recordset

Posted on 2000-04-01
6
316 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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…
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 …
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…
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…

867 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

15 Experts available now in Live!

Get 1:1 Help Now