vba search code via form

AC-Dev

What say you, good sir?
Local time
Today, 14:50
Joined
Jun 20, 2011
Messages
81
I want to create a way to search through the entire database for records that have all or part of the keyword
that the user enters in ANY field of ANY table. i have a DCount() function
in there as well to show the user how many records are in each table. from there
they would click a button which corresponds to one of the tables so they can open up those selected records.
the DCount formula here does not seem to be working. when the button is clicked,
an append query will run to populate the table before it displays.

Code:
Private Sub btnSearch_Click()   
Dim db                      As DAO.Database   
Dim tdf                     As DAO.TableDef   
Dim varRecordCount(1, 44) As Variant   
Dim i As Integer      

Set db = CurrentDb()    
For Each tdf In db.TableDefs     
varRecordCount(0, i) = tdf.Name     
varRecordCount(1, i) = DCount("*", tdf.Name, "* ='" & Me.txtSearchString & "'")     
i = i + 1   
Next  

Set db = Nothing   
Set tdf = Nothing  
End Sub

on another note, i have thought of another way to do this as well but
but i still cannot seem to figure it out.

My idea is to use the keyword that the user enters and go through each
form using the same 'For loop' and have an append query which will populate
a set of 'search tables' and THEN use the DCount method to display the number
of hits to the user.

i think the first option will be a little more efficient since it does not
run unnecessary queries that the user does not want to see.

my main problem i suppose is i don't know how to use the Dcount function or
an append query that will search for records in any field as opposed to a
specific field (which i have already done).

sorry that this is long winded. any advise?
 
Last edited:

Users who are viewing this thread

Back
Top Bottom