Solved

Searching Records in an Access Table on DBGRID

Posted on 1998-08-24
5
147 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
  • 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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Macro which automatically sends attachment to Outlook 14 78
passing parameter in sql procedure 9 65
Copy a row 12 64
IF ELSE Statement in Excel Macro VBA 16 75
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…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
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…

828 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