Making a search tool

  • Thread starter Thread starter Wired
  • Start date Start date
W

Wired

Excuse me for asking a "newbie" question...but, I'm new to using
vb.net. I have a database I have created using Access tables.
I would like to create a Search box similar to the built in one in
access that allows you to click on a field and type in the search
string and it brings up the related record. Any ideas how to do this
or maybe where I can find more information on how to do it?
Thanks in advance!!
 
What you need to do is create the SQL query on the fly, and I'll warn you
that it's not difficult, but tedious. Something like

dim Criteria as String

If len(<firstControl.Text>) > 0 then
Criteria = "<fieldName> = " & <firstControl>.Text
End If
If len(<secondControl.Text>) > 0 then
End IF
If len(Criteria) > 0 then
Criteria &= "and <fieldname> = " & <secondControl>.Text
Else
Criteria = '<fieldname> = " & <secondControl>.Text
End If
End If
.... repeat for each control

dim qryString as String = "<SELECT whatever...>"
If len(Criteria) > 0 then
qryString &= "WHERE " & criteria"
EndIf

....execute the query and process the results


Rather than a long bit of repetitive text, you can loop through the Controls
collection of the form, but frankly, because of the hassle of storing the
fieldname somewhere, and sorting out the fields that don't apply (like the
Search button), I find it easier to just type it out. But then, I type fast
<g>.

HTH


--
Rebecca Riordan, MVP

Designing Relational Database Systems
Microsoft SQL Server 2000 Programming Step by Step
Microsoft ADO.NET Step by Step

http://www.microsoft.com/mspress

Blessed are they who can laugh at themselves,
for they shall never cease to be amused...
 
Great answer, Rebecca! Thanks for posting it!

Steven Bras, MCSD
Microsoft Developer Support/Data Access Technologies

This posting is provided "AS IS" with no warranties, and confers no rights.

Microsoft Security Announcement: Have you installed the patch for Microsoft
Security Bulletin MS03-026?  If not Microsoft strongly advises you to
review the information at the following link regarding Microsoft Security
Bulletin MS03-026
http://www.microsoft.com/security/security_bulletins/ms03-026.asp and/or to
visit Windows Update at http://windowsupdate.microsoft.com to install the
patch. Running the SCAN program from the Windows Update site will help to
insure you are current with all security patches, not just MS03-026.
 
Back
Top