473,770 Members | 1,799 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Searching by unique ID text boxes or name combo boxes

114 New Member
I have an Access database of employees.
Each employee has a unique identification number called "BANNER_ID" .
Each employee's last name and first name are in the database but are not unique (obviously).
The data is stored in a table named EMPLOYEE.

I want to create a search option whereby managers can search for an employee by "BANNER_ID"
by entering the number and pressing a command button named "Search".

I want to create an accompanying search option whereby managers can search for an employee
by selecting his or her last name from a combo box (LAST_NAME) and then first name from
another combo box (FIRST_NAME).
When a last name is selected, I would like the combo box of first names to narrow to only
first names that are associated with the selected last name.

I want both search options to be available.

I have been helped with the following code that searches for employees based on their
last name. However, I am having trouble adapting it to work with my new needs listed above.

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdSearch01_Click()
  2.     Dim strStudentRef As String
  3.     Dim strSearch As String
  4.  
  5. 'Check txtSearch01 for Null value or Nill Entry first.
  6.  
  7.     If IsNull(Me![txtSearch01]) Or (Me![txtSearch01]) = "" Then
  8.         MsgBox "Please enter a last name!", vbOKOnly, "Martin DH Message"
  9.         Me![txtSearch01].SetFocus
  10.     Exit Sub
  11. End If
  12. '---------------------------------------------------------------
  13.  
  14. 'Performs the search using value entered into txtSearch01
  15. 'and evaluates this against values in LAST_NAME
  16.  
  17.     DoCmd.ShowAllRecords
  18.     DoCmd.GoToControl ("LAST_NAME")
  19.     DoCmd.FindRecord Me!txtSearch01
  20.  
  21.     LAST_NAME.SetFocus
  22.     strStudentRef = LAST_NAME.Text
  23.     txtSearch01.SetFocus
  24.     strSearch = txtSearch01.Text
  25.  
  26. 'If matching record found sets focus in LAST_NAME and shows msgbox
  27. 'and clears search control
  28.  
  29.     If strStudentRef = strSearch Then
  30.         MsgBox "Match Found For: " & strSearch, , "Martin DH Message"
  31.         LAST_NAME.SetFocus
  32.         txtSearch01 = ""
  33.  
  34.     'If value not found sets focus back to txtSearch01 and shows msgbox
  35.         Else
  36.             MsgBox "Match Not Found For: " & strSearch & " - Please Try Again.", _
  37.             , "Martin DH Message"
  38.             txtSearch01.SetFocus
  39.     End If
  40. End Sub
  41.  
I would appreciate any help available in developing these search options. Thank you!

Martin DH
Mar 22 '07 #1
11 2690
Rabbit
12,516 Recognized Expert Moderator MVP
The Cascading Combo/List Boxes tutorial will help you set up those comboboxes.
Mar 23 '07 #2
martin DH
114 New Member
I have looked over the combo boxes tutorial as well as some other information. I now have a combo box that limits the options in the second combo box, both of which display the selected results in a list (exactly as I wanted it - thank you!). Now, I want to be able to select a record in the list and thereby open another form that contains the detailed information of the record. Here is the code included in my "search" subform:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Load()
  2. On Error Resume Next
  3.    ResetCombos Me
  4. End Sub
  5. Private Sub cmdReset_Click()
  6. On Error Resume Next
  7.    ResetCombos Me
  8. End Sub
  9. Private Sub cboLAST_NAME_AfterUpdate()
  10. On Error Resume Next
  11.    SetListBox Me.lstList, Me.[cboLAST_NAME], Me.[cboFIRST_NAME]
  12. End Sub
  13. Private Sub cboFIRST_NAME_AfterUpdate()
  14. On Error Resume Next
  15.    SetListBox Me.lstList, Me.[cboFIRST_NAME]
  16. End Sub
  17. Private Sub lstList_Click()
  18. On Error GoTo Err_cmdOpen_Click
  19.  
  20. DoCmd.OpenForm "Search/Edit Employee Files", , , "BANNER_ID=" & Me.BANNER_ID
  21.  
  22. Exit_cmdOpen_Click:
  23.     Exit Sub
  24.  
  25. Err_cmdOpen_Click:
  26.     MsgBox Err.Description
  27.     Resume Exit_cmdOpen_Click
  28.  
  29. End Sub
I do believe my problem is in the DoCmd.OpenForm code - still new at this and just not sure how to make it work.

Thank you for your help!

Martin DH
Apr 7 '07 #3
Rabbit
12,516 Recognized Expert Moderator MVP
If Banner_ID is text you have to surround it with quotes, so:
Expand|Select|Wrap|Line Numbers
  1. "'" & Me.Banner_ID & "'"
Apr 7 '07 #4
martin DH
114 New Member
Ha, of course, quotes - thank you.
Everything is working until I select a record from the list box: at this point a dialog box opens asking me to enter a parameter value for Me!BANNER_ID (the text unique ID for these records). If I do not, the record's detail is not retrieved; if I do enter the correct BANNER_ID, the record's detail is pulled up on the opened form.

So, how do I get past this dialog box (ie selecting a record from the list box opens the record's detail immediately).

Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  3. Private Sub Form_Load()
  4. On Error Resume Next
  5.    ResetCombos Me
  6. End Sub
  7. Private Sub cmdReset_Click()
  8. On Error Resume Next
  9.    ResetCombos Me
  10. End Sub
  11. Private Sub cboLAST_NAME_AfterUpdate()
  12. On Error Resume Next
  13.    SetListBox Me.lstList, Me.[cboLAST_NAME]
  14. End Sub
  15. Private Sub lstList_Click()
  16. On Error GoTo Err_cmdOpen_Click
  17.  
  18.     Dim stDocName As String
  19.     Dim stLinkCriteria As String
  20.  
  21.     stDocName = "Search/Edit Employee Files"
  22.  
  23.     stLinkCriteria = "[BANNER_ID]=" & "Me![BANNER_ID]"
  24.     DoCmd.OpenForm stDocName, , , stLinkCriteria
  25.  
  26. Exit_cmdOpen_Click:
  27.     Exit Sub
  28.  
  29. Err_cmdOpen_Click:
  30.     MsgBox Err.Description
  31.     Resume Exit_cmdOpen_Click
  32.  
  33. End Sub
Thank you!
Apr 10 '07 #5
Rabbit
12,516 Recognized Expert Moderator MVP
You misunderstood what I meant about enclosing Banner_ID in quotes. Take a closer look at my previous post.
Apr 10 '07 #6
martin DH
114 New Member
So, now my code is as below; I thought I saw what you were getting at with the quotes. When I select the record from the list box (created by the combo box selection) it simply leaves the first record on screen.

Expand|Select|Wrap|Line Numbers
  1.     Dim stDocName As String
  2.     Dim stLinkCriteria As String
  3.  
  4.     stDocName = "Search/Edit Employee Files"
  5.  
  6.     stLinkCriteria = "[BANNER_ID]=" & "'" & Me![BANNER_ID] & "'"
  7.     DoCmd.OpenForm stDocName, , , stLinkCriteria
Thanks for your help Rabbit.
Apr 17 '07 #7
Rabbit
12,516 Recognized Expert Moderator MVP
Not a problem.
Apr 17 '07 #8
martin DH
114 New Member
Do you have any solution to the new issue, though? When I select the record from the list box (created by the combo box selection) it simply leaves the first record in the database on screen instead of opening the selected record.

Expand|Select|Wrap|Line Numbers
  1.     Dim stDocName As String
  2.     Dim stLinkCriteria As String
  3.  
  4.     stDocName = "Search/Edit Employee Files"
  5.  
  6.     stLinkCriteria = "[BANNER_ID]=" & "'" & Me![BANNER_ID] & "'"
  7.     DoCmd.OpenForm stDocName, , , stLinkCriteria
martin dh
Apr 19 '07 #9
Rabbit
12,516 Recognized Expert Moderator MVP
Do you have any solution to the new issue, though? When I select the record from the list box (created by the combo box selection) it simply leaves the first record in the database on screen instead of opening the selected record.

Expand|Select|Wrap|Line Numbers
  1.     Dim stDocName As String
  2.     Dim stLinkCriteria As String
  3.  
  4.     stDocName = "Search/Edit Employee Files"
  5.  
  6.     stLinkCriteria = "[BANNER_ID]=" & "'" & Me![BANNER_ID] & "'"
  7.     DoCmd.OpenForm stDocName, , , stLinkCriteria
martin dh
It seems then you don't want to use the Banner_ID from the form but the Banner_ID from the listbox. These are not the same thing.
Apr 19 '07 #10

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

Similar topics

1
10619
by: Mike | last post by:
I have a combo box and a text box. Text to be display will be contigent upon what is selected via the combo box. How do I do this? I put the following code in the text box object: var a = get thisField("combobox") If (a==1) { event.value = "Test1"
1
2156
by: Serious_Practitioner | last post by:
This is such a simple problem. I've asked for, and gotten, help with this in the past, and I can't make this work. Once more, please - I want to be able to put a member number (which is the primary key of a table called tblMemberInfo) into a text box on an unbound form and get back, in some other text boxes, other information (name, e-mail address and date of birth, say) from the same table. I also want to get, from a table called...
3
4279
by: Frustrated Developer via DotNetMonster.com | last post by:
I have posted a couple times on here already and found the user community to be very helpful. I took on a project before I realized how difficult a time I'm having working with a database. Assistance would be greatly appreciated! I am trying to allow certain users to be able to preview a database's contents without being able to update which I've accomplished. I've created a "Preview" button and set the datagrid to READ ONLY. Now I want...
2
1796
by: Bill Brinkworth | last post by:
in vb.net 2005, i would like to pull up a name from a database (customers) (i can do this already), then after a name is selected from a combox box, to populate the form's text boxes with with data about that customer. I.E.: if john is selected from the combo, i would like to have his address, city, etc. filled out in the text boxes. I do not want to populate a listbox or datagrid.....I do these easy as pie in Access but i just can not do...
7
2419
by: evilcowstare via AccessMonster.com | last post by:
Hi, I have searched the forum for answers on this and to be honest as a novice I find it a bit confusing so apologies if it is simple. There are some searches that I want to apply to my database. 1. To search for all records between 2 dates and display them in a report 2. To be able to show all records which have a selection against them made from a combo box 3. To be able to combine the two, selecting the option from a combo and then...
2
3624
by: jw01 | last post by:
I have a form in which there is one combo box and three text boxes: Combo Box: -> Item A -> Item B -> Item C TextBox1: TextBox2: TextBox3:
1
2908
by: Dave | last post by:
Hello all, First I'd like to apologize...This post was meant to be put in my previous post, but I tried many times without success to reply within my previous post. Now here goes... I have a main form (RD Form) with 4 combo boxes (i.e. cbo1, cbo2, etc) and a subdatasheet (the subform...let's call it subInfo) below the combo boxes on the RD Form. I hope this eliminates any confusion of the
9
5005
by: Marianne160 | last post by:
Hi, I know there are various answers to this problem available on the web but none of them seem to work for me. I am using Access 2003 to make a form to look up data from a table. I have so far created three combo boxes that cascade down from Name to Project to Date and when this has been chosen I have four textbox fields I want to display based on this selection. I tried linking the last combo box comboDate to update these fields after...
2
4618
by: SHAWTY721 | last post by:
I have a form that contains two combo boxes that are related to each other. I need to find a way to populate my text box based on the criteria of the two combo boxes so the appropriate number appears in the text box.
0
9617
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9454
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10257
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10099
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10037
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9904
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5482
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4007
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3609
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.