Solved

VB Access Linear search

Posted on 2004-04-01
3
552 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
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…

758 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

25 Experts available now in Live!

Get 1:1 Help Now