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. -
Private Sub cmdSearch01_Click()
-
Dim strStudentRef As String
-
Dim strSearch As String
-
-
'Check txtSearch01 for Null value or Nill Entry first.
-
-
If IsNull(Me![txtSearch01]) Or (Me![txtSearch01]) = "" Then
-
MsgBox "Please enter a last name!", vbOKOnly, "Martin DH Message"
-
Me![txtSearch01].SetFocus
-
Exit Sub
-
End If
-
'---------------------------------------------------------------
-
-
'Performs the search using value entered into txtSearch01
-
'and evaluates this against values in LAST_NAME
-
-
DoCmd.ShowAllRecords
-
DoCmd.GoToControl ("LAST_NAME")
-
DoCmd.FindRecord Me!txtSearch01
-
-
LAST_NAME.SetFocus
-
strStudentRef = LAST_NAME.Text
-
txtSearch01.SetFocus
-
strSearch = txtSearch01.Text
-
-
'If matching record found sets focus in LAST_NAME and shows msgbox
-
'and clears search control
-
-
If strStudentRef = strSearch Then
-
MsgBox "Match Found For: " & strSearch, , "Martin DH Message"
-
LAST_NAME.SetFocus
-
txtSearch01 = ""
-
-
'If value not found sets focus back to txtSearch01 and shows msgbox
-
Else
-
MsgBox "Match Not Found For: " & strSearch & " - Please Try Again.", _
-
, "Martin DH Message"
-
txtSearch01.SetFocus
-
End If
-
End Sub
-
I would appreciate any help available in developing these search options. Thank you!
Martin DH
11 2690
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: - Private Sub Form_Load()
-
On Error Resume Next
-
ResetCombos Me
-
End Sub
-
Private Sub cmdReset_Click()
-
On Error Resume Next
-
ResetCombos Me
-
End Sub
-
Private Sub cboLAST_NAME_AfterUpdate()
-
On Error Resume Next
-
SetListBox Me.lstList, Me.[cboLAST_NAME], Me.[cboFIRST_NAME]
-
End Sub
-
Private Sub cboFIRST_NAME_AfterUpdate()
-
On Error Resume Next
-
SetListBox Me.lstList, Me.[cboFIRST_NAME]
-
End Sub
-
Private Sub lstList_Click()
-
On Error GoTo Err_cmdOpen_Click
-
-
DoCmd.OpenForm "Search/Edit Employee Files", , , "BANNER_ID=" & Me.BANNER_ID
-
-
Exit_cmdOpen_Click:
-
Exit Sub
-
-
Err_cmdOpen_Click:
-
MsgBox Err.Description
-
Resume Exit_cmdOpen_Click
-
-
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
Rabbit 12,516
Recognized Expert Moderator MVP
If Banner_ID is text you have to surround it with quotes, so:
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). - Option Compare Database
-
Option Explicit
-
Private Sub Form_Load()
-
On Error Resume Next
-
ResetCombos Me
-
End Sub
-
Private Sub cmdReset_Click()
-
On Error Resume Next
-
ResetCombos Me
-
End Sub
-
Private Sub cboLAST_NAME_AfterUpdate()
-
On Error Resume Next
-
SetListBox Me.lstList, Me.[cboLAST_NAME]
-
End Sub
-
Private Sub lstList_Click()
-
On Error GoTo Err_cmdOpen_Click
-
-
Dim stDocName As String
-
Dim stLinkCriteria As String
-
-
stDocName = "Search/Edit Employee Files"
-
-
stLinkCriteria = "[BANNER_ID]=" & "Me![BANNER_ID]"
-
DoCmd.OpenForm stDocName, , , stLinkCriteria
-
-
Exit_cmdOpen_Click:
-
Exit Sub
-
-
Err_cmdOpen_Click:
-
MsgBox Err.Description
-
Resume Exit_cmdOpen_Click
-
-
End Sub
Thank you!
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.
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. - Dim stDocName As String
-
Dim stLinkCriteria As String
-
-
stDocName = "Search/Edit Employee Files"
-
-
stLinkCriteria = "[BANNER_ID]=" & "'" & Me![BANNER_ID] & "'"
-
DoCmd.OpenForm stDocName, , , stLinkCriteria
Thanks for your help Rabbit.
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. - Dim stDocName As String
-
Dim stLinkCriteria As String
-
-
stDocName = "Search/Edit Employee Files"
-
-
stLinkCriteria = "[BANNER_ID]=" & "'" & Me![BANNER_ID] & "'"
-
DoCmd.OpenForm stDocName, , , stLinkCriteria
martin dh
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. - Dim stDocName As String
-
Dim stLinkCriteria As String
-
-
stDocName = "Search/Edit Employee Files"
-
-
stLinkCriteria = "[BANNER_ID]=" & "'" & Me![BANNER_ID] & "'"
-
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.
Sign in to post your reply or Sign up for a free account.
Similar topics |
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"
|
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...
|
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...
|
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...
|
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...
| |
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:
|
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
|
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...
|
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.
|
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...
|
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,...
| |
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...
|
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...
|
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,...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |