473,406 Members | 2,847 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.

Search Functions

Hi

I need to create a form whereby users can search for information from multiple forms, and then open a particular record within that form. I currently have a 'Main Menu' with buttons that open forms, but they always open on the first record and the only way to find the one you're looking for is by going through each one. So my questions:

1) How do I create a search button on the main menu that will search within each form and open that record/s?

2) How do I create a search that will search for non-exact matches? For example - search for 'Grange' and it will open '2 Grange Place' and 'Grange House'.

Thanks, Louisa
Feb 17 '17 #1

✓ answered by PhilOfWalton

OK, I don't like it because if you have 4 text boxes, 1 to open each form, you might just as well open the form anyway.

If you insist
Let's call the Text boxes TxtContact, TxtTenant etc
Lets call the corresponding forms FrmContacts, FrmTenants etc.

So here is an example of the code (I'll explain it in a moment
Expand|Select|Wrap|Line Numbers
  1. Private Sub TxtContact_AfterUpdate()
  2.  
  3.     Dim Fltr As String
  4.  
  5.     Fltr = "ContactName like " & Chr$(34) & "*" & TxtContact & "*" & Chr$(34)
  6.  
  7.     DoCmd.OpenForm "FrmContacts"
  8.     Forms!FrmContacts.Filter = Fltr
  9.     Forms!FrmContacts.FilterOn = True
  10.  
  11. End Sub
  12.  
The first line builds a filter and if we are looking for a text value, we must surround it with double quotes.
So if you typed Toys in the text box, the Filter would be
ContactName Like "*Toys*"
That would find anything with Toys in the ContactName

The other lines open the contact form and apply the filter

Phil

6 1217
gnawoncents
214 100+
louisam, the second part is easy. If you are using a text box for searching, then having the user press a button to initiate a search, you could simply add wildcards (*) to the beginning and end of the search string. Something like:

Expand|Select|Wrap|Line Numbers
  1. dim strSearch as String
  2. strSearch = "*" & me.ctlYourTextBox & "*"
  3.  
You would then be able to use the string (strSearch in the example above) to find matches containing whatever was typed into the search box.

Regarding the first question, the way to do this is to use VBA to cycle through each of the records on each form in turn. If there will ever only be one match, you can simply stop when it is found and run the code to open that form on that record. If there is the possibility of having more than one match, you'll have to decide how you want to handle that.

The Bytes article on Finding a Specific Record Programmatically can get you started. https://bytes.com/topic/access/insig...ogrammatically

There are also lots of other examples on how to create a search to find the record you're looking for.
Feb 17 '17 #2
PhilOfWalton
1,430 Expert 1GB
The first part is very vague as to what you want. Are you implying that you have a form on which you select a record (Using a combo box?) and then when you open any one of a number of forms from your Main Menu, you want that form to open at the selected record?

Phil
Feb 17 '17 #3
Hi gnawoncents
Thanks for this but I have no idea how to do that! I'm a very basic computer user and so where do I put that code?! What's a VBA?!
Thanks!

Hi PhilOfWalton
Ok, so I have a form as a main front page that users will automatically see when they open access. On here I was trying to add search boxes to look into each of the forms that I've created for different information (Properties, Contacts, Tenants, Applicants). However the main page form will only allow me to search for exact matches and only use one set of data from a table. I need it to be able to search for non exact and multiple tables.

All and any help much appreciated, thanks!
Feb 27 '17 #4
PhilOfWalton
1,430 Expert 1GB
It's really difficult to understand what you want. Are you suggesting a text box in which you type something, and if it approximately matches any field in one of your tables a form will open showing that record? What do you want to do when it partially matches fields from more than one table? Open all the relevant forms?

Surely you know whether you are looking for information from your properties, contacts, tenants or Applicants.
Is there a relationship between these tables?

Gnawoncents has given the correct coding for a search.
VBA is Visual Basic for Applications and is code that is pretty essential for Access applications. Basically they start a chain of events when you do something. For Example having entered entered something in your search box, pressing the Enter Key starts the searching process.
You can also use Macros, but they are not as versatile as VBA and much harder to find out what is going wrong, so I strongly advise against them

Phil
Feb 27 '17 #5
Hi
Yes, a text box in which I can search for a particular property, contact, tenant or applicant. I'm presuming that there will need to be 4 different text boxes in order to search through the 4 different tables. Some of the names of these can be quite long so rather than having to type 'Channel Island Toys' every time it would be handy to just type 'Toys' (as it happens they are the only tenant with 'Toys' in their name.

There are lots of relationships between the tables - the property table will have the name of the tenant (and vice versa), the tenants will have the name of the main contact, the contacts will be the owners of the properties etc.

I am sure that the coding is correct - but how/where do I type it?!

Louisa
Feb 27 '17 #6
PhilOfWalton
1,430 Expert 1GB
OK, I don't like it because if you have 4 text boxes, 1 to open each form, you might just as well open the form anyway.

If you insist
Let's call the Text boxes TxtContact, TxtTenant etc
Lets call the corresponding forms FrmContacts, FrmTenants etc.

So here is an example of the code (I'll explain it in a moment
Expand|Select|Wrap|Line Numbers
  1. Private Sub TxtContact_AfterUpdate()
  2.  
  3.     Dim Fltr As String
  4.  
  5.     Fltr = "ContactName like " & Chr$(34) & "*" & TxtContact & "*" & Chr$(34)
  6.  
  7.     DoCmd.OpenForm "FrmContacts"
  8.     Forms!FrmContacts.Filter = Fltr
  9.     Forms!FrmContacts.FilterOn = True
  10.  
  11. End Sub
  12.  
The first line builds a filter and if we are looking for a text value, we must surround it with double quotes.
So if you typed Toys in the text box, the Filter would be
ContactName Like "*Toys*"
That would find anything with Toys in the ContactName

The other lines open the contact form and apply the filter

Phil
Feb 27 '17 #7

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

Similar topics

1
by: rick.huby | last post by:
I want to include a site search facility on my company website. I have had a look at some of the solutions out there which seem great, but are all written using non Accessibility compliant code...
0
by: Huihong | last post by:
Please check out our source code search engine here, http://www.codase.com e.g., search main method,...
2
by: intl04 | last post by:
Is it possible to create an Access database that searches on multiple fields or can process multiple search keywords (for a photos database) or is it best to just use third-party software such as...
8
by: Huihong | last post by:
Please check out our newly released source code search engine here, http://www.codase.com e.g., search socket method call,...
0
by: Huihong | last post by:
Please check out our source code search engine here, http://www.codase.com e.g., search the "main" method,...
3
by: .Net Sports | last post by:
I'm able to find info for using input parameters for stored procedures to do inserts and update type SQL functions in asp.net (vb.net), but I need to find something that will use input parameters...
3
by: Rachelle | last post by:
I'm developing a webpage interface for the employees I work with that will allow them to search the database for things. I have everything else set up, but i'm having problems actually developing...
5
by: James Stroud | last post by:
Hello All, I'm using pyinstaller 1.0 (stable) on win32xp and it is not able to find the codec for several encodings (hex, base64, etc.). I resorted to writing my own for hex, just to see if I...
5
by: Deano | last post by:
Perhaps this has been asked before but there might be some up to date thinking about this. I really need a better search function for my asset register. I allow assets to be entered and tracked...
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?
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.