473,419 Members | 1,647 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,419 software developers and data experts.

How to create Search form for database.

50
Hello I would like to create a search form for my database that searches by:

First
Last
Contact Number
Street
City
State
Zip

What is the easiest way possible to accomplish this? I guess I should mention I have a table called tblcustomerinformation. I would like the search to list possible matches and from that list I would like to be able to click and open the record.

Thank you
Aug 22 '07 #1
25 150682
Stang02GT
1,208 Expert 1GB
Hello I would like to create a search form for my database that searches by:

First
Last
Contact Number
Street
City
State
Zip

What is the easiest way possible to accomplish this? I guess I should mention I have a table called tblcustomerinformation. Once the search is completed I will like it to open the matching record.

There are a couple different ways you can do this...

1.You can have text boxes where the users enter search criteria and then press a "search" button
2.You can have a combo box preform your search. The user can either type in what they want to search for or select from a list

I personally like the "search button" method. I am sure others memebers of TSDN will have other ideas but if you would like to do this let me know and I can help you out.


Have a good one!
Aug 22 '07 #2
ali3n8
50
There are a couple different ways you can do this...

1.You can have text boxes where the users enter search criteria and then press a "search" button
2.You can have a combo box preform your search. The user can either type in what they want to search for or select from a list

I personally like the "search button" method. I am sure others memebers of TSDN will have other ideas but if you would like to do this let me know and I can help you out.


Have a good one!

Search Button is exactly what im looking for.
Aug 22 '07 #3
Stang02GT
1,208 Expert 1GB
Search Button is exactly what im looking for.

Ok well here is what you are going to need to do

Once you are have your form created with all the feilds you would like displayed, you are going to create a BOUND text box. (Bound means that it is connected with a feild in a table) in this example i will use LastName.

1.Once you have created your bound text box ( i can tell you how to do this if you don't know). You will wnat to create a blank button next to it.
2. Once you have created the button place this code in the "OnClick" event of the button. You are going to have to put the appropreate names in the corrisponding places

Expand|Select|Wrap|Line Numbers
  1. Private Sub ButtonsName_Click()
  2.    If IsNull(TextboxesName) = False Then
  3.       Me.Recordset.FindFirst '[FeildYourSearchingFor]=' & TextboxesName
  4.       Me!TextboxesName = Null
  5.       If Me.Recordset.NoMatch Then
  6.          MsgBox "No record found", vbOKOnly + vbInformation, "Sorry"
  7.             Me!TextboxesName = Null
  8.       End If
  9.    End If
  10. End Sub
This code will search, and if there is no result it will pop up a message telling the user there was not record found, and it will clear the txt box after the search is completed.
Aug 22 '07 #4
ali3n8
50
Ok well here is what you are going to need to do

Once you are have your form created with all the feilds you would like displayed, you are going to create a BOUND text box. (Bound means that it is connected with a feild in a table) in this example i will use LastName.

1.Once you have created your bound text box ( i can tell you how to do this if you don't know). You will wnat to create a blank button next to it.
2. Once you have created the button place this code in the "OnClick" event of the button. You are going to have to put the appropreate names in the corrisponding places

Expand|Select|Wrap|Line Numbers
  1. Private Sub ButtonsName_Click()
  2.    If IsNull(TextboxesName) = False Then
  3.       Me.Recordset.FindFirst '[FeildYourSearchingFor]=' & TextboxesName
  4.       Me!TextboxesName = Null
  5.       If Me.Recordset.NoMatch Then
  6.          MsgBox "No record found", vbOKOnly + vbInformation, "Sorry"
  7.             Me!TextboxesName = Null
  8.       End If
  9.    End If
  10. End Sub
This code will search, and if there is no result it will pop up a message telling the user there was not record found, and it will clear the txt box after the searc is completed.
Do I need to create a new table or can I just create a new form and label the text boxes on that?
Aug 22 '07 #5
ali3n8
50
How do I create a bound text box. I created a new text box on a form and it says unbound.
Aug 22 '07 #6
Stang02GT
1,208 Expert 1GB
To create a bound text box you are going to need to....

1. Right Click on the text box
2. Select Properties
3.Click on the Data tab
4. There should be a drop down with selections of the feilds in your table(if your form is bound to a table)

To bind a form to a table
1. In the properties menu for the Form do to the data tab
2.Click the drop down box and select the table you would like the form bound to
Aug 22 '07 #7
Stang02GT
1,208 Expert 1GB
If im not explaing things good enough here are a couple sites you can take a look at there are very good and provide a lot of detailed information about how to do things in Access

Search Form

How To Articles

More How To's
Aug 22 '07 #8
ali3n8
50
I created a form and dragged the fields I wanted to the form. I create the command button and also pasted what you gave me on clickevent. I get errors when I click the button.

MS Access can't find the macro 'private Sub ButtonsName_Click() if IsNull(Contact Number)= False Then Me.
Aug 22 '07 #9
Stang02GT
1,208 Expert 1GB
I created a form and dragged the fields I wanted to the form. I create the command button and also pasted what you gave me on clickevent. I get errors when I click the button.

MS Access can't find the macro 'private Sub ButtonsName_Click() if IsNull(Contact Number)= False Then Me.
Did you name the button "ButtonsName"?

Access names it by default something like" Command_15"
Aug 22 '07 #10
ali3n8
50
To name the button, In design view I right click on the button and then select the all tabe. There is a field there called name in the field I inputed "ButtonsName". Is that correct?
Aug 22 '07 #11
Stang02GT
1,208 Expert 1GB
Yes, but you can name the button whatever you'd like. Just make sure that whatever you name it to you change it in the code, because if you don't then Access doens't know where to look when you press the button
Aug 22 '07 #12
ali3n8
50
Can you highlight for me what areas in this code i need to edit I may have edited it incorrectly. Here is what I did below:
Expand|Select|Wrap|Line Numbers
  1. Private Sub ButtonsName_Click()
  2.    If IsNull(Contact Number) = False Then
  3.       Me.Recordset.FindFirst '[Contact Number]=' & Contact Number
  4.       Me!Contact Number = Null
  5.       If Me.Recordset.NoMatch Then
  6.          MsgBox "No record found", vbOKOnly + vbInformation, "Sorry"
  7.             Me!Contact Number = Null
  8.       End If
  9.    End If
  10. End Sub
Aug 22 '07 #13
Stang02GT
1,208 Expert 1GB
Expand|Select|Wrap|Line Numbers
  1. Private Sub ButtonsName_Click()
  2.    If IsNull(Contact Number) = False Then
  3.       Me.Recordset.FindFirst '[Contact Number]=' & Contact Number
  4.       Me!Contact Number = Null
  5.       If Me.Recordset.NoMatch Then
  6.          MsgBox "No record found", vbOKOnly + vbInformation, "Sorry"
  7.             Me!Contact Number  = Null
  8.       End If
  9.    End If
Change the bolded names to something different, and make sure you don't put spaces.

Try something like ContactNum
Aug 22 '07 #14
ali3n8
50
Expand|Select|Wrap|Line Numbers
  1. Private Sub ButtonsName_Click()
  2.    If IsNull(Contact Number) = False Then
  3.       Me.Recordset.FindFirst '[Contact Number]=' & Contact Number
  4.       Me!Contact Number = Null
  5.       If Me.Recordset.NoMatch Then
  6.          MsgBox "No record found", vbOKOnly + vbInformation, "Sorry"
  7.             Me!Contact Number  = Null
  8.       End If
  9.    End If
Change the bolded names to something different, and make sure you don't put spaces.

Try something like ContactNum

They bolding did not appear on your post.
Aug 22 '07 #15
Stang02GT
1,208 Expert 1GB
Can you highlight for me what areas in this code i need to edit I may have edited it incorrectly. Here is what I did below:
Expand|Select|Wrap|Line Numbers
  1. Private Sub ButtonsName_Click()
  2.    If IsNull(Contact Number) = False Then
  3.       Me.Recordset.FindFirst '[Contact Number]=' & Contact Number
  4.       Me!Contact Number = Null
  5.       If Me.Recordset.NoMatch Then
  6.          MsgBox "No record found", vbOKOnly + vbInformation, "Sorry"
  7.             Me!Contact Number  = Null
  8.       End If
  9.    End If
  10. End Sub

Is this anybetter?...........................
Aug 22 '07 #16
ali3n8
50
So here is what my code looks like now:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Contactbut_Click()
  2.    If IsNull(Contactnum) = False Then
  3.       Me.Recordset.FindFirst '[Contact Number]=' & Contactnum
  4.       Me!Contactnum = Null
  5.       If Me.Recordset.NoMatch Then
  6.          MsgBox "No record found", vbOKOnly + vbInformation, "Sorry"
  7.             Me!Contactnum = Null
  8.       End If
  9.    End If
  10. End Sub
Aug 22 '07 #17
Stang02GT
1,208 Expert 1GB
Ok...did it work??????????
Aug 22 '07 #18
ali3n8
50
No it didnt unfourtunately would you mind if I emailed my db to you? Or if there is a way for me to post it here or tranfer to you via IM.
Aug 22 '07 #19
Jim Doherty
897 Expert 512MB
No it didnt unfourtunately would you mind if I emailed my db to you? Or if there is a way for me to post it here or tranfer to you via IM.
Ali,

I have this afternoon created an AC2000 database for you that deals specifically with your introduced question. It is a flexible method of searching across any number of fields in combination with each other. If you use your imagination with the demo sample you will quickly realise that it can be adapted for many areas. The sample assumes you are familar with VBA code (and you eventually will be)
I have only just joined this forum this afternoon and cannot see an upload button? and to post the code in itself might be to intensiveif you PM me I,ll send you the database in zipped format ( and anyone else for that matter who might benefit as a developer)
Aug 22 '07 #20
Stang02GT
1,208 Expert 1GB
No it didnt unfourtunately would you mind if I emailed my db to you? Or if there is a way for me to post it here or tranfer to you via IM.

Sure PM me and i'll give you my e-mail address
Aug 22 '07 #21
Jim Doherty
897 Expert 512MB
Anyone who might benefit in reading this:

As requested attached is the Access 2000 Search demo database I refer to earlier in this thread. (a zip file so extract to anywhere on your hard drive) There a a couple of other goodies thrown in like exporting the resultset to excel and so on.

Take a look at the code behind the forms It works for version 2000 and 2003 (note however if version 2007 it will fail due to an apparent lack of response in that a subform will only show the first record albeit the recordsource of the subform is being set at runtime)

Regards

Jim
Attached Files
File Type: zip searchdemo.zip (196.3 KB, 7827 views)
Feb 11 '11 #22
Very Nice creation and works in 2007 also
Thank you all who involving

Sandip
Feb 12 '11 #23
Jim Doherty
897 Expert 512MB
In response to a request I received recently I am reposting the file I contributed 3 years ago in 2011 it is in now in ACCDB format for those of you so wishing to learn from the techniques therein.

Basically ignore the previous MDB format and go with this ACCDB format rejigged for Access 2007 through to Access 2013

Regards

Jim Doherty
Attached Files
File Type: zip SearchDemo.zip (116.9 KB, 3337 views)
Mar 3 '15 #24
NeoPa
32,556 Expert Mod 16PB
For anyone else wishing to ask questions related to anything included in this thread, but not directly related to the original question of the thread and by the original poster, these are hijacks if posted in this thread, and will be deleted, but are perfectly reasonable questions when posted in their own thread separately.

You can even post links to this thread from your new one AND, if you think it will help to be noticed by members already involved in this thread, you can also post in here with a link to your new question thread. All that you mustn't do is to ask your new question in here.
Mar 12 '15 #25
I know this is an old thread, but THANK YOU for this. It is extremely helpful.
Jan 10 '19 #26

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

Similar topics

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...
1
by: kevinray | last post by:
Hi, I have recently started to create an application which pulls data from our asset management database. I am using VB.NET 2003, and the data is on a SQL 2000 server. OS is 2K and XP. I want to...
16
by: StephR | last post by:
Hello, the users on this site seem to be very helpful. I hope you guys can help me. I have been searching for the past 2 weeks on how to create a search form for my database at work. I'm not really...
2
by: MNNovice | last post by:
I am working on a database on my CD collection using Access 2003. Some of the table structures are given below. Table 1 tblMusicCategory Field 1: MusicCategoryID - Auto Number (PK) Field 2:...
1
by: pteargryphon | last post by:
I am creating a database of pavement conditions. I am trying to create a form for a user to be able to search the database based on 2 criteria, Route Number and Town Name. I have the form set up...
1
by: NLR2008 | last post by:
Hi there, Can anybody help me and provide me with a SIMPLE solution to create a search form in Access 2003. I have created a database for Finance Payments and want to enable the user to...
11
by: woodey2002 | last post by:
This problem is driving me crazy. Hello there, i am trying to create a search form for records in my access database. The search form will contain text boxes and a multi select list box. The user...
8
by: munkee | last post by:
Hi everyone, I am using the following code adapted from Allen Browne: 'Purpose: This module illustrates how to create a search form, _ where the user can enter as many or few...
1
by: rachbret | last post by:
Hi, I created a database with a table that has customer info - including sales history. I want to create a form so that i can search based on various criteria (first name, last name, purchase date,...
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
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
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
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...
1
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.