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

filter combo box to show unique names in linked table

Hello,
I have a data entry form for a table with information about buildings and am having a problem making a combo box do what I want. I would like to make the combo box show a list of unique bldg mgmt company names and then to open a building management company form to show all records with this name, so the user can find the correct branch location to select. Then, upon closing the building management company form, the active/selected record will be returned in the combo box on the buildings form.

The main form is called frmBldgs. The table that frmBldgs is based on is called tblBldgs.
tblBldgs includes:
Field 1: BldgID – autonumber primary key
Field 2: BldgNm – name of the building
Field 3: BldgMgmtCoIDFK – foreign key linking to a table about the building mgmt company
… and a number of other attributes about the building.

The table detailing the Building Management Company is called tblBldgMgmtCo.
tblBldgMgmtCo includes:
Field 1: BldgMgmtCoID – autonumber primary key
Field 2: BMCNmIDFK – foreign key linking to a table listing building mgmt company names
Field 3: Addr1IDFK – foreign key linking to a table listing street addresses

The reason I have a separate building mgmt company name table is that there can be more than one company with the same name (e.g. branch locations with different addresses).

The table listing the Bldg Mgmt Company names is called tblBldgMgmtCoNm.
tblBldgMgmtCoNm includes:
Field 1: BMCNmID – autonumber primary key
Field 2: BldgMgmtCoName – unique company name

On frmBldgs I have a combo box, called cboBldgMgmtCo, with control source BldgMgmtCoIDFK. Right now, cboBldgMgmtCo shows building names, but it shows all unique records in tblBldgMgmtCo, which means that bldg mgmt company names repeat if there is more than one branch (with a different address and therefore a different record).
The current row source query for cboBldgMgmtCo is:
Expand|Select|Wrap|Line Numbers
  1. SELECT DISTINCT tblBldgMgmtCo.BldgMgmtCoID, tblBldgMgmtCoNm.BldgMgmtCoName
  2. FROM tblBldgMgmtCoNm INNER JOIN tblBldgMgmtCo ON tblBldgMgmtCoNm.BMCNmID = tblBldgMgmtCo.BMCNmIDFK
  3. ORDER BY tblBldgMgmtCoNm.BldgMgmtCoName;
  4.  
Column Count is 2
Column Width is 0”;1”
Bound Column is 1
This results is the name of the building mgmt companies are listed in the combo box, but – as I mentioned above – there are repeats if more than one record in tblBldgMgmtCo has the same name.

I have also added an AfterUpdate Event for cboBldgMgmtCo to open the building management company form, called frmBldgMgmtCo (based on tblBldgMgmtCo). The code is as follows:
Expand|Select|Wrap|Line Numbers
  1. Private Sub cboBldgMgmtCo_AfterUpdate()
  2.     Dim stDocName As String
  3.     Dim stLinkCriteria As String
  4.  
  5.     stDocName = "frmBldgMgmtCo"
  6.  
  7.     stLinkCriteria = "[BldgMgmtCoID]=" & Me![cboBldgMgmtCo]
  8.     DoCmd.OpenForm stDocName, , , stLinkCriteria
  9.  
This opens frmBldgMgmtCo to the record with the same BldgMgmtCoID, but does not show all records with the same bldg mgmt company name.

I want cboBldgMgmtCo to list the potential building mgmt company names once each and then open frmBldgMgmtCo filtered to show all records with that name (BMCNmIDFK) so the user can find the correct branch to select. The user can then select the correct BldgMgmtCo record (or create a new one) and when they close frmBldgMgmtCo, the active / selected record will be returned in cboBldgMgmtCo on frmBldgs.

To do this, I assume I need to change the query for the row source to somehow only show unique names, though I cannot quite figure out the correct code. Then, I think I need to change the AfterUpdate event so that it will open frmBldgMgmtCo filtered to the field BMCNmIDFK of the bldg mgmt company that equals the name chosen in the combo box. Finally, I need a button on frmBldgMgmtCo to close the form, once the correct record is selected and add an OnClick Event to this that returns the correct record in cboBldgMgmtCo on frmBldgs. I have a button that closes the form, called btnClose,but have not created the code to ensure the correct record is returned in the combo box.

I am new to VBA and Access and so need help on how to write the code to achieve these ends. Any help is greatly appreciated! Thanks in advance.

Bridget
Oct 16 '07 #1
2 3876
nico5038
3,080 Expert 2GB
Hmm, it won't be possible to have a "Distinct Name" combobox and position later on one specific company as the needed CompanyID won't (can't) be present in the combobox.

Personally I would however take an entirely different approach.
I would create an "unbound" (not table related) Mainform ans all companies as subform. Then I would place the company "distinct" combobox on the mainform and use the afterupdate event to filter the subform.
Besides the subform you can add "Action" buttons like [Add], [Update], [Delete], [Print], etc..
For the filtering it's perhaps even better to explain the use of the right-click popup to filter, as that's even more versatile. It will allow a LIKE '*inc* selection.

Checkout my sample database:
http://www.geocities.com/nico5038/xS...tAction-97.zip
and my right-click instruction I give my users:
http://www.geocities.com/nico5038/xR...nstruction.zip

Nic;o)
Oct 17 '07 #2
Hmm, it won't be possible to have a "Distinct Name" combobox and position later on one specific company as the needed CompanyID won't (can't) be present in the combobox.

Personally I would however take an entirely different approach.
I would create an "unbound" (not table related) Mainform ans all companies as subform. Then I would place the company "distinct" combobox on the mainform and use the afterupdate event to filter the subform.
Besides the subform you can add "Action" buttons like [Add], [Update], [Delete], [Print], etc..
For the filtering it's perhaps even better to explain the use of the right-click popup to filter, as that's even more versatile. It will allow a LIKE '*inc* selection.

Checkout my sample database:
http://www.geocities.com/nico5038/xS...tAction-97.zip
and my right-click instruction I give my users:
http://www.geocities.com/nico5038/xR...nstruction.zip

Nic;o)
Hello Nic;o,
Thank you for your response. Sorry for my delayed reply. I was pulled onto another project for a few days. (and, of course, it takes a while to get your head back into the Access world once you've taken a break!)

I will take a look at your sample database to see how its functionality might work for me and will repost if I have questions.
Thanks again,
Bridget
Oct 19 '07 #3

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

Similar topics

3
by: Richard | last post by:
Hi, I have a form based on a table. When I filter the form I want to run a report based on the same table with the same filter as the form. No problem until I want to filter a combo box where...
1
by: Access User | last post by:
Here is my situation: I have two tables linked together in a many-to-many relation through an interum table. It looks like this... Title TitleTopic Topic...
6
by: Ralph2 | last post by:
Some time ago with a lot of help from this group I made a reasonably successful database to keep track of our shop drawings. However the searching mechanism is too complicated for the occasional...
3
by: Stewart | last post by:
Hi all! My (relatively small) database holds data on staff members and the projects (services) that they are assigned to. In my form frmStaff, I have a list of staff members - it is a...
11
by: Bob | last post by:
I am in the process of upgrading an Access database to SQL Server (and climbing that learning curve!). The wizard happily upgraded all the tables and I can link to them OK using ODBC. The...
7
by: Takeadoe | last post by:
Gang, I have searched this group and have found several other occasions where folks have experienced the same problem that is described below. "I have access to several databases where I have...
2
by: Pablo | last post by:
I have a Continuous Form based on the following table: sku, description, categoryId, subCategoryId I restrict the initial dataset to include one value for categoryId, but it may include...
5
by: favor08 | last post by:
I have a database and I am using a function that captures the shortname and displays it on the mainMenu screen. What I want to do is filter the information on the "past due" screen based on the...
2
by: jambonjamasb | last post by:
What I am trying to do is have a combo box which allows me to filter for a certain field in a subform. I can't think how to do this and have tried with the follwoing code. Basically the field in...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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...
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...

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.