Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Search Function

Posted on 2003-11-07
8
Medium Priority
?
164 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
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!

 
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 750 total points
ID: 9709358
Thanks for the feedback and good luck
0

Featured Post

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.

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 …
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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 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…
Suggested Courses

636 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