473,399 Members | 4,177 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,399 software developers and data experts.

search form

Hi,

I'm kinda stuck right now with one of my forms and wondering if someone could help me with this. Basically what I need to create is a search form for users to be able to search using part Id or part Description. for example if user type in 10* in the part ID text box, then it should show all parts with part ID started with 10 in a data grid on the same form
I have a form with txtpartID, txtDescription and search button. My question is how can I display the results? do I need to create subform for it? I'm using access 2003. Your help in this is very much appreciated.
Jan 21 '08 #1
10 1635
jyoung2
32
Yes you should use a subform
If you are creating a seperate search form with "txtpartID, txtDescription and search button" then you can have your query look to txtpartID and txtDescription and have the button call "me.subformname.requery" and it will display the results.
Jan 21 '08 #2
How can I do that? should I put that code on the search button?
Jan 21 '08 #3
jyoung2
32
Create a query in design mode,
you place [forms]![YourFormName]![YourFieldName] into the criteria fo your query

requery the subform with your button on click event using this code.

me.subformname.requery
Jan 21 '08 #4
jaxjagfan
254 Expert 100+
In the criteria of your query put something like this

Like "*" & [Forms]![frmSearch]![txtVIN] & "*"

This is a quote from something I do here - modify to suit your needs.

You no longer have to add the *. It is assumed. And this criteria would return all with a 10 anywhere in the partnumber whether beginning, middle, or end.

You can do this via an unbound textbox and a command button. If the form is based on the query with the criteria above then all the command button needs for code is

Me.Requery

You would enter a value and click the button.

Wildcards like you are using have to use the word "Like"
Jan 21 '08 #5
In the criteria of your query put something like this

Like "*" & [Forms]![frmSearch]![txtVIN] & "*"

This is a quote from something I do here - modify to suit your needs.

You no longer have to add the *. It is assumed. And this criteria would return all with a 10 anywhere in the partnumber whether beginning, middle, or end.

You can do this via an unbound textbox and a command button. If the form is based on the query with the criteria above then all the command button needs for code is

Me.Requery

You would enter a value and click the button.

Wildcards like you are using have to use the word "Like"
Thank you for the reply and I'm almost there. The only problem I have right now is if there's a part ID start with 10 and there's no description for that part, it won't show up on the search. I need for users to be able to search by part id or description. Is there a way for access to show all data with part id 10 no matter if the description is null or show all part id if the description is null?
Jan 22 '08 #6
jyoung2
32
In your query

Part one
Expand|Select|Wrap|Line Numbers
  1. Field    yourfildDesc
  2. Criteria    LIKE *  & [forms]![YourFormName]![YourFieldName] & "*"
  3. Or    LIKE *  & [forms]![YourFormName]![YourFieldName] & "*"
Part 2
Expand|Select|Wrap|Line Numbers
  1. yourtxtpart
  2. LIKE *  & [forms]![YourFormName]![YourFieldName2] & "*"
  3.  
  4. LIKE *  & [forms]![YourFormName]![YourFieldName2] & "*"
Prt 3
Expand|Select|Wrap|Line Numbers
  1. [forms]![YourFormName]![YourFieldName]
  2. not is null
  3. NOT is null
  4.  is null
prt4
Expand|Select|Wrap|Line Numbers
  1. [forms]![YourFormName]![YourFieldName2]
  2. not is null
  3. is null
  4. Not is null
take each part an put them into the query
The logic is if a field is null it ignores it for the query if both fields have data both feilds are used if only 1 has data it ignores the other

Place them side by side and it makes more sense if this doesn't help I can try to explain it better or I could maybe send a screen shot but it would not paste.
Jan 22 '08 #7
NeoPa
32,556 Expert Mod 16PB
Check out Using "&" and "+" in WHERE Clause.
Jan 22 '08 #8
Check out Using "&" and "+" in WHERE Clause.
Thank you for all your help. but the code that you gave me is still not working (probably I'm missing something) Here is what I did: On the query (that showed all the data on the subform) on the partID criteria:
Expand|Select|Wrap|Line Numbers
  1. Like "*" & [forms]![frmsearch]![txtid] & "*" or  Like "*" & [forms]![frmsearch]![txtid] & "*" 
  2. and on the description criteria, I put:  Like "*" & [forms]![frmsearch]![txtdesc] & "*" or  Like "*" & [forms]![frmsearch]![txtdesc] & "*"
but I don't really know where I should put the code (part 3 and part 4). Is it on the search button? because my search button code is DoCmd.Requery "search subform"
Jan 22 '08 #9
NeoPa
32,556 Expert Mod 16PB
You've quoted my post, but I suspect from what you've posted yourself that you haven't checked it out yet.

I'm afraid jyoung2's suggestion is not quite right (although they're trying to be helpful so I have no complaint with that). Any strings in SQL should be enclosed in quotes ('). See Quotes (') and Double-Quotes (") - Where and When to use them.

NB. If you're creating a string to pass to SQL you need to remember that the VBA will understand some of the quotes (") and pass on the others to SQL. For a string value in SQL you need to make sure that the SQL gets the string WITH the SQL quotes in.
Jan 22 '08 #10
jaxjagfan
254 Expert 100+
Thank you for all your help. but the code that you gave me is still not working (probably I'm missing something) Here is what I did: On the query (that showed all the data on the subform) on the partID criteria:
Expand|Select|Wrap|Line Numbers
  1. Like "*" & [forms]![frmsearch]![txtid] & "*" or  Like "*" & [forms]![frmsearch]![txtid] & "*" 
  2. and on the description criteria, I put:  Like "*" & [forms]![frmsearch]![txtdesc] & "*" or  Like "*" & [forms]![frmsearch]![txtdesc] & "*"
but I don't really know where I should put the code (part 3 and part 4). Is it on the search button? because my search button code is DoCmd.Requery "search subform"
Make sure the the criteria is entered on seperate lines (if on the same line as each other AND is implied. if on different rows then OR is implied)

Switch to SQL View, copy and paste your query for us to see pls.

The SELECT portion should be similar to
Expand|Select|Wrap|Line Numbers
  1. SELECT * FROM parts
The WHERE portion should look similar to below.
Expand|Select|Wrap|Line Numbers
  1. WHERE partid Like "*" & [forms]![frmsearch]![txtid] & "*"
  2.  OR description Like "*" & [forms]![frmsearch]![txtdesc] & "*" 
As previously posted you will have to learn to handle Null or no entries.

This gets a little more complicated if your users have multiple fields to choose from. 99% of the time a user knows a partial partnbr or partial part description and would want to search by one or the other.

The complication is on you, the developer. You may need to set the datasource of the form via code using SQL statements now. You need to decide if you want to give the user the option to search by multiple fields or only one at a time.

Insert an "Option Group" in your search form. Option 1 could be show all number. Option 2 could be part number. Option 3 could be part description, etc. You could have a lot of options. Give the "Option Group" control a good name - opt1 - Access calls it Frame0 if the first frame or option group.

You only need one Textbox for search criteria - i called it txtSearch.

Within the Code for the search button:

Expand|Select|Wrap|Line Numbers
  1. Dim strSQL as String
  2. Dim strCrit as String
  3. Dim iNull as integer
  4.  
  5. strSQL = "Select * From tblParts"
  6.  
  7. If Me.opt1 > 1 Then
  8. If isnull(Me.txtSearch)
  9. Msgbox "You must enter search ctriteria!"
  10. Me.txtSearch.Setfocus
  11. Exit Sub
  12. End If
  13. End If
  14.  
  15. Select Case Me.opt1
  16. Case 1
  17. strCrit = ";"
  18. Case 2
  19. strCrit = " WHERE partid Like "*" & [forms]![frmsearch]![txtSearch] & "*" & ";"
  20. Case 3
  21. strCrit = " WHERE  description Like "*" & [forms]![frmsearch]![txtSearch]  & "*" & ";"
  22. End Select
  23.  
  24. Me.RecordSource = strSQL & strCrit
  25.  
  26.  
Don't let us make this seem impossible with all of the code and SQL geek speak. :D
Jan 22 '08 #11

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

Similar topics

1
by: Les Juby | last post by:
A year or two back I needed a search script to scan thru HTML files on a client site. Usual sorta thing. A quick search turned up a neat script that provided great search results. It was fast,...
2
by: CharitiesOnline | last post by:
Hello, I have set this script up to add paging to a search results page. Which on the first page works fine. I calculates how many pages there should be depending on the number of results returned...
1
by: bdawg | last post by:
what i want to do is create several radio buttons and a textbox for searching purposes. the search will perform a search depending on which button the user selects. here is what i have now: ...
1
by: N. Graves | last post by:
Hi, I want to have a Search Dialog box that has several text box and fields to build a search and display the results in a form. I can do everything that I need to if I us a report but I would...
9
by: Christopher Koh | last post by:
I will make a form which will search the database (just like google interface) that will look/match for the exact name in the records of a given fieldname. Any suggestions on how to make the code?
8
by: Steph | last post by:
Hi. I'm very new to MS Access and have been presented with an Access database of contacts by my employer. I am trying to redesign the main form of the database so that a button entitled...
1
Merlin1857
by: Merlin1857 | last post by:
How to search multiple fields using ASP A major issue for me when I first started writing in VB Script was constructing the ability to search a table using multiple field input from a form and...
5
by: Fran Jakers | last post by:
Hello all, I'm new to all this and I could really use some help. I've searched the web but cannot find an answer. I have an HTML form with 3 radio buttons and a search field that calls a...
2
by: Mark | last post by:
Hi All, I am creating a music database for a friend and have run into a problem. Within the ALBUM table, I wanted to store the ARTIST_ID rather than the ARTIST_NAME. To do this, I intended to have...
12
by: iahamed | last post by:
Hi Everyone, I got two parts of my advance search to work, I am running out of Logic to connect the third. My mind is in swing! Pleaseeeeeeeee Help me. I have 3 Fiels to search, the First two...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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:
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.