Solved

Search Function

Posted on 2003-11-07
8
155 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 76

Expert Comment

by:GrahamSkan
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks for the feedback and good luck
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

743 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

17 Experts available now in Live!

Get 1:1 Help Now