Solved

Search Function

Posted on 2003-11-07
8
159 Views
Last Modified: 2010-08-05
I need to be able to search a column of numbers or a column of text values, for a specific number or name in an Access database using a VB form (using a text box to receive the input) and a Search button event handler to launch the search.  I do not know how to do this, any help would be appreciated.  Also, In addition to finding a specific number or name value, once the value is found I need to populate the text boxes that will store the rest of the data from the record.
0
Comment
Question by:bfrancisco
8 Comments
 
LVL 3

Expert Comment

by:NBrownoh
ID: 9706197
if you use an ADODC control to connect to the database you can use SQL statements to query the databse.
SELECT * FROM YourTable WHERE ColumnName = 'SearchVal'
that is one possible sql statement to grab search specific results
0
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 9706353
To use the query:

Adodc1.RecordSource = "Select ...
Adodc1.Refresh

To Populate the text boxes, set (in the properties window), their DataSource as the data control (Adodc1), and each one's Datafield to the field name desired.
0
 

Author Comment

by:bfrancisco
ID: 9707051
Here's my code from the search event handler.  When I enter a number that I know exists in the database, I launch the event handler and it returns with break:

Private Sub btnCmdSrch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCmdSrch.Click
        Dim sql As String
        sql = "SELECT * FROM PRODUCTS WHERE PROD_ID=00001"
        MsgBox(sql)
        Dim btnSrch_cmd As New OleDb.OleDbCommand(sql, Conn)
        btnSrch_cmd.ExecuteNonQuery() ("This is the line my code breaks on")
End Sub

Thanks for taking a look at this.
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 76

Expert Comment

by:GrahamSkan
ID: 9707307
I'm a bit lost here.
Are you using using VB or Access and which versions.
I only know up to VB6 and Access 2000 & have never had to use an OleDB object.
0
 
LVL 1

Expert Comment

by:fsaims
ID: 9707485
Add this command line in your code: -

 Dim sql As String
        sql = "SELECT * FROM PRODUCTS WHERE PROD_ID=00001"
        MsgBox(sql)
        Dim btnSrch_cmd As New OleDb.OleDbCommand(sql, Conn)
'Add this line
Conn.Open()
        btnSrch_cmd.ExecuteNonQuery() ("This is the line my code breaks on")
Conn.Close()
0
 

Author Comment

by:bfrancisco
ID: 9708154
GrahamSkan,
I'm using Vb.Net to create an application.  The application connects to an Access 2000 type database.  The search function will be run from the application, i.e., I trying use a Search command button event handler in a Vb which executes code and an SQL statement which searches through a column in an Access database looking for a specific value.  Once the search function finds the specific value, I want a whole row of data retuned to the Vb form to populate text boxes.

Also, fsaims, I tried your solution but it doesn't work; the code breaks for an unhandled exception error at the Conn.Open() statement.

Thanks for attempting to help.  If each of you can be of further assistance that would be great.  I went out and bought a couple of books today, a Microsoft ADO.NET book by David Sceppa and a VB.NET book by Brian Siler and Jeff Spotts.  I'm hoping to find my solution therein.  Cheers!
0
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 250 total points
ID: 9709358
Thanks for the feedback and good luck
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…

829 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