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.
7 5840
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: - Private Sub but_search_Click()
-
-
Dim db As Database
-
Dim rst As Recordset
-
-
Set db = CurrentDb
-
-
If IsNull(CDCNO) And IsNull(LastName) Then
-
MsgBox "Please enter a search criteria", vbOKOnly
-
CDCNO.SetFocus
-
Exit Sub
-
End If
-
-
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] & "*'))")
-
-
Select Case rst.RecordCount
-
Case Is > 0
-
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"
-
Case Else
-
Results.RowSource = ""
-
MsgBox "Zero records found.", vbOKOnly
-
End Select
-
-
Refresh
-
db.Close
-
End Sub
And this runs when they double click a record: - Private Sub Results_DblClick(Cancel As Integer)
-
Dim SearchString As String
-
SearchString = "CDCNO = '" & Results & "'" & " AND " & "EnrollDate = #" & Results.Column(3) & "#"
-
DoCmd.OpenForm "frm_Demo", , , SearchString
-
End Sub
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
Not a problem, good luck.
Howzit Rabbit
Just one question. Maybe I am just being blind and stupid today, but what does CDCNO in your code refer to?
Thanks
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.
Excellent .Thanks for that reply, that's cleared that one up for me!
Excellent .Thanks for that reply, that's cleared that one up for me!
Not a problem, let us know if you get stuck anywhere.
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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.)...
|
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....
|
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)....
|
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...
|
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...
|
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...
|
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...
|
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...
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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,...
|
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...
|
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...
|
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...
| |