Solved

VB Access Linear search

Posted on 2004-04-01
3
568 Views
Last Modified: 2013-12-25
Hey I need a feature to search a database using a linear search then display the result in the textboxes linked to the data control but I have no clue how to. Can someone give me the code?

Form name = frmeditfile
Data control name = datappointment
Column to search = Telephone Name
Search var = Got from input box.

Thanks
0
Comment
Question by:Mercurtio
3 Comments
 
LVL 8

Expert Comment

by:bramsquad
ID: 10734440
if you are using ado, this could work

dim i as integer, conn as new ADODB.connection, rcd as new ADODB.recordset
dim valuefrominputbox as string
'make sure to open connection to db here


valuefrominputbox = inputbox()
for i = 0 to rcd.recordcount - 1
if rcd.Fields.Item(0).Value = valuefrominputbox then
     me.textbox.text += rcd.Fields.Item(0).Value + vbcrlf
end if
next

the "0" in rcd.Fields.Item(0).Value references the first column, so you would change that to whatever the column is you want to compare.  also, the +vbcrlf just creates a new line, so it would look like this in your textbox

value1
value2
value3

if youre using vb6, use this for the if statement

if rcd![Telephone Name].Value = valuefrominputbox then

someone please correct me if i made any syntax errors, i didnt test this, but i think its right

~bramsquad

0
 

Author Comment

by:Mercurtio
ID: 10736684
I'm not sure what ADO is i'm using the Data control with arrows each side of it to connect to the database then each textbox connects to the data control via Datasource.

I need it to set the data control to the position where it found the item to update all the other text boxes connected to it not put the searchitem in a textbox.
0
 
LVL 45

Accepted Solution

by:
aikimark earned 100 total points
ID: 10739443
AdoDataControl1.Recordset.Find "fieldname = searchvalue"

Note: you will need to add delimiters around searchvalue for text and date field searches.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

749 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