473,660 Members | 2,428 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Filtered Combo Box on the detailed section of a subform

kcdoell
230 New Member
Hello:

I have a form (Default view =single form) with a subform (Default view =continuous forms) embedded into it. In the form I have three controls that display the Division, Working Region & Credit Region. The subform displays the data/records. The record source for both my form and subform is driven by a query, which is the way I filter the records that the end user will see via another form I created.

Everything is working fine but I can not seem to figure something out that I have never done before.

The issue is that the end user can add a new record via my subform. My challenge is that one of the fields that is displayed is called “Product” There are a lot of products to choose from on this drop down list but not as many if the list was filtered by Working Region. The layout of my product table is as follows:

Product:
tblProduct
ProductID = Autonumber
ProductsName = Text
WrkRegID = Number (This is for my one to many relationship; a working region can have many different Products)

Is there a way to filter the list of my product field on my subform for new records?

I was trying to experiment with doing this and can not figure it out. What I did get to work was on the header of my subform I dropped in a combo box and then on the load event of that form wrote the following code:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Load()
  2. 'When the Working Region has been displayed on the form, the appropriate Product list
  3. 'will display in the drop down list of CboProduct
  4.  
  5.   With Me![cboProduct]
  6.     If IsNull(Me!txtWrkReg) Then
  7.       .RowSource = ""
  8.     Else
  9.       .RowSource = "SELECT [ProductsName] FROM tblProduct WHERE [WrkRegID]=" & _
  10.                     DLookup("[WrkRegID]", "tblWrkRegion", "[WrkRegionName] = '" & Me![txtWrkReg] & "'")
  11.     End If
  12.     Call .Requery
  13.   End With
  14.  
  15. End Sub
  16.  
As mentioned this worked. The problem is that the minute I embedded that control “cboProduct” in the detail portion of my subform I do not get any errors, the list will be appropriately populated but if let’s say three records are displaying, the minute I make a selection from cboProduct all of the records will be change to that selection. I only want it to change new records not the old ones.

Does anybody have any idea on how this can be done??

Thanks,

Keith.
Mar 13 '08 #1
14 2334
Stewart Ross
2,545 Recognized Expert Moderator Specialist
Hi Keith. From what you say it would appear that the combo is not bound to one of the fields in your subform, as unless you are calling an after-update event to update records when you make a selection from the combo it cannot of itself change multiple records - but it can give the appearance that it is.

A subform actually repeats the same set of controls on each row shown on the form, and if one of those is unbound you see the same value repeated on every row. This makes it look like you have changed all records - but as mentioned unless there is an After Update event in use it has not actually done anything at all to your records.

An unbound control is one whose controlsource is blank - one that is not bound to a specific field in your underlying table. If you are embedding an unbound combo box control in the detail section of your subform it's in the wrong place.

Ask yourself what you want the combo to do on your subform, and if that is to provide a list for one of the table values in your subform you will need to bind it to the appropriate field.

By the way, the form load event is fired only when you first open the form - is this the right timing for the conditional recordsource loading in your event code?

-Stewart
Mar 13 '08 #2
kcdoell
230 New Member
Hello:

Let me answer the last question first:

"By the way, the form load event is fired only when you first open the form - is this the right timing for the conditional recordsource loading in your event code?"

Once the end user in on the form the "working region" parameter can not be changed within it, so there is no problem with the load event only firing once.

On another note, I am not yet an advance Access person so please be patient if I don't entirely understand your response.

Let me see if I can better explain the scenario:

Let's say my subform is displaying 3 records that only have 3 fields:
Expand|Select|Wrap|Line Numbers
  1. RecID      Product         ImageDate         Company
  2. 1            ASL           12/12/2005      Richardson Inc.
  3. 2            BAA           11/10/2005      Peterson Corp.
  4. 3            DWW           08/21/2005      Harolds Inc.
Currently in my “Product” field it is displaying the full gamut of Products (when you click on the combo box) because its row source is pointing to my Product table (tblProduct). So if I add a new record, once I key into the product field my choices will be the full list. What I am trying to do is have it so that the choices is limited by the working region. In essence, I am trying to filter the list by working region so the end user can only select those now limited choices.

How would one do that? Do you have an idea I could try?

Thanks,

Keith.
Mar 13 '08 #3
Stewart Ross
2,545 Recognized Expert Moderator Specialist
Hi Keith. You can use a combo for selection of the product field, a combo which is bound to the value of the product field itself. To do this you delete your existing product field on the subform and replace it with a combo, using the combowizard to build the basic query for the recordsource from your product table. This can be tweaked with a WHERE clause similar to the one in your form load event to filter for the region. The DLookup should not be necessary.

The SQL for this will look something like:
Expand|Select|Wrap|Line Numbers
  1. SELECT [Product], [ProductsName] FROM tblProduct WHERE [WrkRegionName] = '" & Me![txtWrkReg] & "'"
assuming I am interpreting your fields correctly.

The main difference between this and what you had before is that the rowsource is returning the product ID and the product name. It is the product ID which is the value that you store in the subform table, not the name of the product. The combo wizard will itself recommend that you hide the key value - showing the product name, but recording the product ID instead. This is done by setting the ID column width of the combo to 0 to hide the column.

-Stewart
Mar 13 '08 #4
kcdoell
230 New Member
I have been trying to get this to work all day......... My problem is that it is looking for the ID number but is only finding the name of the Working Region...
Mar 14 '08 #5
Stewart Ross
2,545 Recognized Expert Moderator Specialist
I have been trying to get this to work all day......... My problem is that it is looking for the ID number but is only finding the name of the Working Region...
Hi Keith. Is it the case that you do not have a product ID field in your table? If you don't it would explain why you are only returning the product name. You need to bind the combo to whatever is the key field of your product table; if this is the product name, then you wll only need the one column in your combo and you should just return the name and nothing else.

In relational table design there is always a primary key which uniquely identifies rows in a table. There is a good article on table design and normalisation in the HowTo section of the forum, at http://www.thescripts.com/forum/thread585228.html

-Stewart
Mar 14 '08 #6
kcdoell
230 New Member
Okay:

So what I did was go into the combo box of "Product" and put the row source as follows:

SELECT [ProductName] FROM tblProduct WHERE [WrkRegID] = '" & Me![txtWrkReg] & "'"

What I am getting is a syntax error message when I click on the drop down box. I believe my other problem is that txtWrkReg is displaying the name where my tblProduct is looking for the Working Region Name.

Could that be the reason I am having the syntax errors or is the code missing something?

Keith.
Mar 14 '08 #7
kcdoell
230 New Member
Hi Keith. Is it the case that you do not have a product ID field in your table? If you don't it would explain why you are only returning the product name. You need to bind the combo to whatever is the key field of your product table; if this is the product name, then you wll only need the one column in your combo and you should just return the name and nothing else.

In relational table design there is always a primary key which uniquely identifies rows in a table. There is a good article on table design and normalisation in the HowTo section of the forum, at http://www.thescripts.com/forum/thread585228.html

-Stewart

Below is my table layout:

Product:
tblProduct
ProductID = Autonumber
ProductsName = Text
WrkRegID = Number (This is for my one to many relationship; a working region can have many different Products)

As noted earlier it does have a unique ID number and it has a relationship with the working region ID (One to many).

Does that answer your question????
Mar 14 '08 #8
kcdoell
230 New Member
I just read the article. I am not an expert but I believe that my structure is normalized with my 1to1 and 1toMany relationships.
Mar 14 '08 #9
Stewart Ross
2,545 Recognized Expert Moderator Specialist
Below is my table layout:

Product:
tblProduct
ProductID = Autonumber
ProductsName = Text
WrkRegID = Number (This is for my one to many relationship; a working region can have many different Products)

As noted earlier it does have a unique ID number and it has a relationship with the working region ID (One to many).

Does that answer your question????
Hi Keith. Thank you for the clarification and your previous post. You do indeed have an ID field which is unique; and you are right about the region name/ number mismatch causing the drop-down error. We will need to restore the use of the Dlookup to get back the region number from the region name, although this should not have been necessary.

I'll post back shortly with revised SQL for your combo.

-Stewart
Mar 14 '08 #10

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

Similar topics

2
2540
by: Kelly | last post by:
I have a subform that display requisition information. One of the fields in the subform is a combo box that shows who requested the requisition. The users can change who requested the requisition and I would like to only have them be able to choose active employees. So, I have written the query for the rowsource for this combo box, which is based on an employees table, to look at all active employees and the employee that is currently...
3
5336
by: Mike Jakes | last post by:
I hope that someone can offer a little advice on this one - I've searched the group but can't find an answer. I think that I'm doing something really stupid or missing something trivial, but see what you can make of this... I have a main form "Events" that contains a tab control. The tab control has 7 pages. The 7th page (named "Boats") contains a subform called "BoatEventssubform". On this sub-form are two combo boxes, named...
6
7471
by: Rick | last post by:
I have a main form called frmDemo with a subform frmStageTrack_Sub. On the subform is a Combo Box CboTermID. The frmDemo is tied to tblDemo and the frmStageTrack_Sub is tied to tblStageTrack. What I would like to do is when a new record is created in frmDemo I would like to set the CboTermID on the subform to a default value, say 1, without the user having to set focus on the subform and selecting an item from the combo box. Right now...
2
1902
by: docsix | last post by:
I am having trouble populating a combo box in a subform. Currently I have two combo boxes on a single form that works. This is my current setup: Table:Facilities - FacilityID ... FacilityType 1 ............ Bus 2 ............ Library Table: Additional DetailID .... Details .............. FacilityID 1 ..............TImetable .......... Bus
4
2900
by: virtualgreek | last post by:
Dear All, First of all I would like to take the time to thank you all for your efforts and time spent at this wonderful forum. I have found it very helpful with numerous examples available for every level of user. I am facing a rather weird behaviour with a combo box on a subform (Continuous form). I have two tables. Order and Order_Details. The master form is based on the Orders tables and the details form (subform) is based on the...
0
1143
by: Oerf | last post by:
I have a form were I select the deal name and therein a subform in which a have a combo box to specify the type of input for the selected deal. This combo box should show my the types that are valid for the deal I selected. The valid choices for all deals are contained in one table. Can someone tell me I can filter the row input of valid choices with respect to the chosen deal name? Thanks for your help!
5
2314
by: Penstar | last post by:
I have a Combo Box on a Subform which works perfectly when the suborm is opened on its own. However, when I open the Main form Containing the Subform, and try to use the Combo Box it comes up with box "Enter Paramater Value" Forms!KS_OrdersEnter_F!KS_OrdersEnter_SF!ProductID. Main form Name KS_OrdersEnter_F Subform Name KS_OrdersEnter_SF Forms Linked by field
12
3641
by: Supermansteel | last post by:
I have a combo box called cmb_category. I then have the SQL statement as such: SELECT Originations_Categories.Category, Originations_Categories.Category_ID FROM Originations_Categories WHERE (((Originations_Categories.Product_ID)=1)) ORDER BY Originations_Categories.Category; And I have Column Count as 1 and bound column set to 2 for the category_ID. What I am trying to do is Select one of the 8 Categories in my Combo box and it...
1
1539
by: Yousaf Shah | last post by:
Hello everybody i am building my dataabse for patient record. my main record entry form "patients Record" is a tabbed form with tabsas follows tab "NOK" having subform NOK, tab "History/Exam" having subform History and subsubform Exam, tab "Admission" having subform Admission all the subforms are subform to main form "Patients Record" Now on subform History, there is a bound combo box named "AdmNeed" with values; "Admission not...
0
8428
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
8341
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
8851
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
8754
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...
0
7362
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6181
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4343
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2760
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
1740
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.