By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,594 Members | 3,215 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,594 IT Pros & Developers. It's quick & easy.

filter combo box to show unique names in linked table

P: 59
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
Share this Question
Share on Google+
2 Replies


nico5038
Expert 2.5K+
P: 3,072
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

P: 59
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

Post your reply

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