Solved

Searching Records in an Access Table on DBGRID

Posted on 1998-08-24
5
149 Views
Last Modified: 2010-04-30
I want to search records just like you can in Excel in the same format.  I am using a DB Grid and have it linked to a data control.  I tried manipulating the MSVB5 Example of Findfirst,etc, and there was a problem in the data conversion of the two recordset types.  To sum it up I want  the user to search the first field in my 'table' and have this table updated so that, that matched record is highlighted.
0
Comment
Question by:qurashi
[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
  • 2
  • 2
5 Comments
 
LVL 1

Expert Comment

by:blwatkins
ID: 1430676
How many records in the grid are you talking about?

How are you accessing the database?, (Datacontrol, etx?)

tell me if im correct in this statement?
  You want the user to type in a text box something to search for in one field?  Then press a search button and it will search the data and heighlight the row of data in your grid that matches his search text?

if above is correct let me know? and I will give exact details on how to achieve it?  If not correct my statement and I'll give details on that.

Thanks brad.

0
 
LVL 14

Expert Comment

by:waty
ID: 1430677
If I anderstand well, here is an answer

You don't have to use FindFirst, you should create a new query :

dim sSQL   as String
dim record as Recordset

sSQL = "Select Yourrecord From YourTable"
set record = DB.OpenRecordset(sSQL, DAO.dbOpenForwardOnly)
.

To update your table

sSQL = "Update YourTable Set yourSum = (Select Sum(Yourrecord) From YourTable)"

DB.Execute sSQL




0
 

Author Comment

by:qurashi
ID: 1430678
I should rephrase my question as I was quite vague.

I am working on a program that opens up a large database with many tables/queries.  These tables/queries are displayed on my DBGrid, and are changed when the user wants to view other information, eg. Customer Records as a table and Employee Records as a table.

I want the user to search the first field of the open table on the DBgrid.  When the record is found, I want the first field highlighted and the grid updated as such, just like working with a large MSExcel sheet.  

This searching will be accessed through a toolbar button, and will have a prompt.  

Thanks very much for a response!
0
 

Author Comment

by:qurashi
ID: 1430679
Wasn't what I was looking for, my fault as I was vague
0
 
LVL 1

Accepted Solution

by:
blwatkins earned 100 total points
ID: 1430680
The following is code related to searching thru a dbgrid to
find text that matches text put in by the user to search for.
The following code is attached to a "Search" Command button.


Private Sub Command1_Click()
Dim SearchVAL   As String
Dim Count       As Integer
Dim ISFound     As Boolean


  ISFound = False
  SearchVAL = InputBox("Enter Value to Find: ", "Find Record")
 
  DBGrid1.Col = 0
  For Count = 0 To Data1.Recordset.RecordCount - 1
    DBGrid1.Row = Count
    If DBGrid1.Text = SearchVAL Then
      ISFound = True
      Exit For
    End If
  Next
  If ISFound Then
    MsgBox "Found"
   Else
    MsgBox "Search Value was not Found!", vbInformation
  End If
End Sub

0

Featured Post

Independent Software Vendors: 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

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…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…
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…

733 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