473,406 Members | 2,549 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

How to create custom search box

Hi all

Does anyone know how to create a search box on a form where you can for instance enter a name or something like a vehicle registration which then queries the database and if found and selected, autofills a form with all relevant data relating to the selection you made?

I have searched The Scripts and also googled this , but cannot seem to find anything.

Hopes this makes sense.

Thanks in advance for any help on this.
Mar 20 '07 #1
7 5840
Rabbit
12,516 Expert Mod 8TB
Here's what I use. I have a form with 2 unbound textboxes, a search button, and a listbox that lists the results.

This runs when they click the search button:
Expand|Select|Wrap|Line Numbers
  1. Private Sub but_search_Click()
  2.  
  3. Dim db As Database
  4. Dim rst As Recordset
  5.  
  6. Set db = CurrentDb
  7.  
  8. If IsNull(CDCNO) And IsNull(LastName) Then
  9.     MsgBox "Please enter a search criteria", vbOKOnly
  10.     CDCNO.SetFocus
  11.     Exit Sub
  12. End If
  13.  
  14. Set rst = db.OpenRecordset("SELECT CDCNO, LastName, FirstName, EnrollDate, ParoleDate FROM tbl_Demo WHERE (((LastName) Like '*" & [Forms]![frm_Find]![LastName] & "*')) AND (((CDCNO) Like '*" & [Forms]![frm_Find]![CDCNO] & "*'))")
  15.  
  16. Select Case rst.RecordCount
  17.     Case Is > 0
  18.         Results.RowSource = "SELECT CDCNO AS [CDCR #], LastName AS [Last Name], FirstName AS [First Name], EnrollDate AS [Enrollment Date], ParoleDate AS [Parole Date] FROM tbl_Demo WHERE (((CDCNO) Like '*" & [Forms]![frm_Find]![CDCNO] & "*')) and (((LastName) Like '*" & [Forms]![frm_Find]![LastName] & "*')) ORDER BY LastName, FirstName, EnrollDate"
  19.     Case Else
  20.         Results.RowSource = ""
  21.         MsgBox "Zero records found.", vbOKOnly
  22. End Select
  23.  
  24. Refresh
  25. db.Close
  26. End Sub
And this runs when they double click a record:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Results_DblClick(Cancel As Integer)
  2.   Dim SearchString As String
  3.   SearchString = "CDCNO = '" & Results & "'" & " AND " & "EnrollDate = #" & Results.Column(3) & "#"
  4.   DoCmd.OpenForm "frm_Demo", , , SearchString
  5. End Sub
Mar 20 '07 #2
Thanks for that buddy.

I will have a look through the code and see if I can apply it to my database. I will get back if I am struggeling.

Thanks
Mar 21 '07 #3
Rabbit
12,516 Expert Mod 8TB
Not a problem, good luck.
Mar 21 '07 #4
Howzit Rabbit

Just one question. Maybe I am just being blind and stupid today, but what does CDCNO in your code refer to?

Thanks
Mar 22 '07 #5
Rabbit
12,516 Expert Mod 8TB
CDCNO and EnrollDate is how our department uniquely identifies participants. CDCNO is a unique identifier for an individual. SELECT CDCNO is selecting the field called CDCNO from the table tbl_Demo. Me.CDCNO refers to a control on my form that they are typing into to search for part or whole of a CDCNO.
Mar 23 '07 #6
Excellent .Thanks for that reply, that's cleared that one up for me!
Mar 23 '07 #7
Rabbit
12,516 Expert Mod 8TB
Excellent .Thanks for that reply, that's cleared that one up for me!
Not a problem, let us know if you get stuck anywhere.
Mar 23 '07 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Larry R Harrison Jr | last post by:
I have Access 97. I know how to create custom command bars. I typically create pull-down menus; seldom do I create toolbars. But I have a case where I would; in fact, I would like to have a menu...
2
by: Dennis C. Drumm | last post by:
This is a restatement of an earlier post that evidently wasn't clear. I am building a custom MessageBox dialog that has, among other things, a few new button options (yes to all, no to all, etc.)...
0
by: Shailaja Kulkarni | last post by:
Hi All, I am new to component development. I want to create custom control to arrange contained controls in form of polygonal shape. The objects are placed in separate panel on the some form....
1
by: Pablo Salazar | last post by:
Hi People. Somebody can help me. Some time ago I began to develop database project for a college. Actually control don't adjust that I need. I need to create a control from beginning ( from 0)....
2
by: Homa | last post by:
Hi all, Does any one know how to create a custom window like the control panel of PowerDVD and WinAmp in C#? If I need to use C++ Library to do this, where should I head to? Thanks for...
6
by: John Lau | last post by:
Hi, I am looking at the MS KB Article 306355: HOW TO: Create Custom Error Reporting Pages in ASP.NET by Using Visual C# .NET This article describes how to redirect errors to a custom html...
0
by: bdog_jdog | last post by:
Hi All, I don't get too much in the way of responses from the PortalServer.Development group, so wondering if any C# folks here are familiar with SharePoint development. Just trying to bang...
0
by: robert.hundt | last post by:
Hi, I created a Google Custom Search Engine for searching on: "Software / Compilers / Optimization" This is basically a regular full Google search giving preference to certain sites. Of...
2
by: =?Utf-8?B?V29ua28gdGhlIFNhbmU=?= | last post by:
Hello, I have an existing (WPF) Class Library project that I'd like to add a WPF Custom Control to. However, when I try to Add New Item, that isn't one of the available options. Perhaps this...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.