• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 154
  • Last Modified:

Searching Records in an Access Table on DBGRID

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
qurashi
Asked:
qurashi
  • 2
  • 2
1 Solution
 
blwatkinsCommented:
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
 
watyCommented:
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
 
qurashiAuthor Commented:
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
 
qurashiAuthor Commented:
Wasn't what I was looking for, my fault as I was vague
0
 
blwatkinsCommented:
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now