473,240 Members | 1,727 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,240 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 3868
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: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

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.