Solved

Searching Records in an Access Table on DBGRID

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

762 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