473,516 Members | 2,711 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How can I make a combo box value on a subform based on the combo value on a main for

37 New Member
I have a main form with a subform on the main form. The main form have a couple of text boxes and a combo box. The subform have a couple of text boxes and a combo box. I want the values in the combo box on the subform to be based on the values in the combo box on the main form.

For instance, the combo box (cboCartStatus) on the main form will have the values: INSERVICE, AVAILABLE, UNKNOWN, DISPOSED and
the combo box (cboCartEvent) on the subform will have the values: DELIVERY, DISPOSAL, FOUND, MISSING, REMOVAL, REPAIR, STOLEN, UNKNOWN.

if the cboCartStatus is "INSERVICE", the only values that need to show in the cboCartEvent on the subform is "DELIVERY", "REPAIR"

if the cboCartStatus is "AVAILABLE", the only value that need to show in the cboCartEvent on the subform is "REMOVAL"
Nov 16 '11 #1
21 2074
NeoPa
32,558 Recognized Expert Moderator MVP
That can be done a number of ways, but which way to choose depends on information you haven't included in your question.

Such as :
  1. How are you populating the ComboBox on the main form?
  2. How are you populating the ComboBox on the sub-form?
  3. When and how are the values of these ComboBoxes changed (under what circumstances)?
Nov 17 '11 #2
mrsgwen90
37 New Member
On both the Main Form and the Sub Form the combo box is being populated from a table.
A table called tbl_CartInfoCodes. it is using the fields: Code_Desc and Code_Type.

Here is the Query that I am using right now for the combo box on the Main form :
Expand|Select|Wrap|Line Numbers
  1. SELECT dbo_tbl_CartInfoCodes.Code_Desc, dbo_tbl_CartInfoCodes.Code_Type
  2. FROM dbo_tbl_CartInfoCodes
  3. WHERE (((dbo_tbl_CartInfoCodes.Code_Type)="CartStatus"))
  4. ORDER BY dbo_tbl_CartInfoCodes.Code_Type;
here is the query that I am using right now for the combo box on the Sub form which shows all of the values :
Expand|Select|Wrap|Line Numbers
  1. SELECT DISTINCT dbo_tbl_CartInfoCodes.Code_Desc, dbo_tbl_CartInfoCodes.Code_Type
  2. FROM dbo_tbl_CartInfoCodes
  3. WHERE (((dbo_tbl_CartInfoCodes.Code_Type)="CartEvent"));
PS. The user chooses a value from the combo box
Nov 17 '11 #3
sierra7
446 Recognized Expert Contributor
Hi
The query in your first combo does not make sense to me. I don't believe that you need the WHERE clause
Expand|Select|Wrap|Line Numbers
  1. WHERE (((dbo_tbl_CartInfoCodes.Code_Type)="CartStatus"))
  2.  
This will only allow values in your main combo where [Code_Type] equals the literal text "CartStatus". This may be right but I am guessing not.

I believe that the bound field in cboCartStatus should be your second column, [Code_Desc] and this should also be its Control_Source. The query can be simply;-
Expand|Select|Wrap|Line Numbers
  1. SELECT dbo_tbl_CartInfoCodes.Code_Desc, dbo_tbl_CartInfoCodes.Code_Type
  2. FROM dbo_tbl_CartInfoCodes
  3. ORDER BY dbo_tbl_CartInfoCodes.Code_Type;
  4.  
You are doing cascade filtering but your problem is exacerbated by needing to filter for the child record in your subform.
I believe that the query in cboCartEvent should be
Expand|Select|Wrap|Line Numbers
  1. SELECT DISTINCT dbo_tbl_CartInfoCodes.Code_Desc, dbo_tbl_CartInfoCodes.Code_Type
  2. FROM dbo_tbl_CartInfoCodes
  3. WHERE (((dbo_tbl_CartInfoCodes.Code_Type)='" & _
  4. Me.Parent.Code_Type & "'));" 
You may need to force a Save Record after making your choice in you main form
Expand|Select|Wrap|Line Numbers
  1. Public Sub cboCartStatus_AfterUpdate()
  2. DoCmd.RunCommand acCmdSaveRecord
and you may need to do a Me.Requery in the On_Enter event for cboCartEvent.
See how you get on.
S7
Nov 17 '11 #4
mrsgwen90
37 New Member
OK,I forgot to explain. The CartInfoCode tables looks like this:

Code_Types:
CartDisposal
CartEvent
CartRepair
CartStatus
ServiceEvent
ServiceStatus

and for each Type there is a Code_Desc

CartDisposal - Damaged, Fell In Truck, Burned, Other Missing, Stolen
CartEvent - Disposal, Stolen, Delivery, Removal, Repair, Missing, Found, Unknown
CartRepair - Lid, Wheel, Axle, Pin, Bar, Hinge, Other
CartStatus - InService, Available, Disposed, Unknown
ServiceEvent - Service Start, Service Stop, Bill Cart, Bill Final
ServiceStatus - Active, NotActive, Vacant, Private, Suspended
Nov 17 '11 #5
NeoPa
32,558 Recognized Expert Moderator MVP
It seems clear that there was a lot more important detail missing from the question than I'd even realised. I'm guessing that what determines the values you wish [cboCartEvent] to include is actually the [Code_Type] of the row selected in [cboCartStatus].

As S7 says in his post, you could handle this with cascaded filtering, but I expect doing that properly (I would never advise replacing the whole SQL in code when all that needs changing is the WHERE clause as that is a recipe for problems when any changes are made later to the design.) might be a bridge too far for you right now (It would involve manipulating the existing SQL string and changing just the relevant part of the WHERE clause).

With this in mind I would suggest that you include a DLookup() call using a reference to [cboCartStatus] in your SQL for [cboCartEvent] of the form :
Expand|Select|Wrap|Line Numbers
  1. SELECT DISTINCT 
  2.        [Code_Desc]
  3.      , [Code_Type]
  4. FROM   [dbo_tbl_CartInfoCodes]
  5. WHERE  ([Code_Type] = DLookup('[Code_Type]',
  6.                               '[dbo_tbl_CartInfoCodes]',
  7.                               '[Code_Desc] = ''' & Forms!MainForm!cboCartStatus & '''')
Admittedly, this is all based on the assumption I made earlier as to what your question should have been, but if that isn't the case then I'm sure you can clarify by asking your question properly so that it does make sense.

PS. This was prepared over the time you last posted, but thankfully your post confirms my guess rather than contradicting it so it should work.

PPS. You may well need to call a .Requery of [cboCartEvent] in the AfterUpdate event procedure of [cboCartStatus].
Nov 17 '11 #6
mrsgwen90
37 New Member
ok I see your point but I guess I'm still not explaining it correctly. I need to basically tell it what values to use in the Subform combo box based on the value selected in the main form combo for instance.

If INSERVICE is selected in the main form combo box. I need the subform combo box to only show the values DELIVERY, REPAIR (which are CartEvent type descriptions).

If AVAILABLE is selected in the main form combo box. I need the subform combo box to only show the values REMOVAL, FOUND (which are CartEvent type descriptions).
Nov 17 '11 #7
NeoPa
32,558 Recognized Expert Moderator MVP
MrsGwen90:
ok I see your point but I guess I'm still not explaining it correctly.
No. Not even now, and not even close.

I see no correlation between the data (Showing that data was the first helpful step in the thread) and what you're requesting. This means it's not only not explained, but also that it's not even guessable from all the information so far posted.

You use "CartEvent type description" in your explanation but never explain what that even refers to.

Your data shows the following [Code_Type] along with the associated [Code_Desc]s.
Expand|Select|Wrap|Line Numbers
  1. CartStatus - InService, Available, Disposed, Unknown
In what possible logic could that indicate a particular subset of the [Code_Desc]s found for :
Expand|Select|Wrap|Line Numbers
  1. CartEvent - Disposal, Stolen, Delivery, Removal, Repair, Missing, Found, Unknown
It seems you need to take a step back and consider explaining the question properly, such that when we read it we'll have a clue as to what you're trying to achieve. Please read it back to yourself before posting and ask yourself if you could understand enough about the problem just by reading what you propose to post.
Nov 17 '11 #8
mrsgwen90
37 New Member
I'm sorry, I have explained it the best way that I could....
Let me try again..

I have a Form that has a subform embedded in it. On the main form I have a combo box called "cboCartStatus". On the subform I have a combo box called "cboCartEvent". When a value is chosen in the cboCartStatus combo box, the values in the cboCartEvent (subform) has to correlate. Basically I'm trying to Cascade the combo boxes.

The RowSource for both of the combo boxes is a query from the table tbl_CartInfoCodes. The table has 3 fields: ServiceStatusID, Code_Type, and Code_Desc.

There are code descriptions for each code type. For instance, For the Code_Type CartEvent, there are 8 code_desc (Stolen, Disposal, Delivery, Removal, Repair, Missing, Found, Unknown) and for Code_Type CartStatus there are 4 code_desc (Unknown, InService, Disposed, and Available).

So if the user choses the "InService" from the cboCartStatus combobox (combo on main form), then the cboCartEvent combo box (combo on the subform) need to only show 2 of the code_desc ("Delivery" and "Repair").

Now here is where the difficulty comes in. The person who created the application did not properly normalize the CartInfoCodes table (IMO, which is the RowSource for both of the combo boxes.

I have attached a copy of the table.
Attached Files
File Type: zip CartInfoCodes.zip (49.8 KB, 100 views)
Nov 18 '11 #9
NeoPa
32,558 Recognized Expert Moderator MVP
MrsGwen90:
So if the user choses the "InService" from the cboCartStatus combobox (combo on main form), then the cboCartEvent combo box (combo on the subform) need to only show 2 of the code_desc ("Delivery" and "Repair").
This repeats the instructions you gave us already. What is still missing is the link between the two.

Let me put that another way :
How do I, an outsider, know which [Code_Desc] values should be available in [cboCartEvent]? What is the correlation between a selection of "InService" from [cboCartStatus] and the values available in [cboCartEvent]?

No-one can put logic into code if that logic is never explained in the first place. Does that start to make sense? Can you see now what you need to tell us?
Nov 18 '11 #10
mrsgwen90
37 New Member
ok let me try and explain......

The entire form deals with Carts. The correlation is When a Cart has a status of "InService" then the event that can take place with the Cart is it has been "Delivered" OR it has been "Repaired" while it is still in Service.

On the Other hand, if a cart has a status of "Available" that means the cart has either been "Removed" or if the cart was lost and they found it - the CartEvent will be "Found" which will make it Available again to use.

I can easily put all of the CartEvents in the dropdown but I want to make sure the user doesn't choose one that doesn't relate to the CartStatus.

I have attached a copy of what the form looks like..
Attached Files
File Type: zip Doc1.zip (62.7 KB, 97 views)
Nov 18 '11 #11
NeoPa
32,558 Recognized Expert Moderator MVP
What I have worked out from looking at the attached document (which would have been much easier if you'd just posted the information as text in a post) is that each ComboBox uses only a small subset of the records in the table.

[cboCartStatus] uses only those records with a [Code_Type] of "CartStaus" and [cboCartEvent] uses only those records with a [Code_Type] of "CartEvent". It seems the rest of the data is not related to this question at all. It also seems, best guess, that the other types include in post #5, but not in the document attached, are equally irrelevant to the question. I say best guess as normally such a change of information would mean something (Actually, it wouldn't even occur. If it did it would be rigorously explained). If I'm right though, it is just random noise in this case.

This is some progress against the tide, but we still have no idea why the selection of "INSERVICE" from [cboCartStaus] should cause the normal list for [cboCartEvent] of "STOLEN; DISPOSAL; DELIVERY; REMOVAL; REPAIR; MISSING; FOUND; UNKNOWN" to be reduced to a list consisting simply of "DELIVERY; REPAIR".
Nov 18 '11 #12
mrsgwen90
37 New Member
The list of cboCartEvent need to be reduced to consist of only Delivery, Repair because even though they are CartEvents those are the only two relevant to INSERVICE and it would eliminate the user from chosing one of the others. Just like Repair and Found would only be relevenat to AVAILABLE and so on...
Nov 18 '11 #13
NeoPa
32,558 Recognized Expert Moderator MVP
I'm sure you know which go with which, but until you explain the correlation to us then we don't. I'm struggling to see why this has become such a struggle. Am I not communicating in simple English? I really cannot see what is so confusing.
Nov 18 '11 #14
mrsgwen90
37 New Member
I guess I am not understanding what you mean by correlation.
Nov 18 '11 #15
NeoPa
32,558 Recognized Expert Moderator MVP
I can work with that (I think).

The correlation is a set of rules which map the selected item from [cboCartStatus] onto the required subset of available items for [cboCartEvent]. We know already that the selection of "INSERVICE" maps to a list of "DELIVERY; REPAIR", but we don't know the subsets for any of the other possible entries.

Typically, this would be handled by an extra field in the table specially designed to handle such a correlation. The complexity of this field would depend on whether or not any individual value could belong to only one such subset or could possibly belong to more than one. I have no idea what your correlation is, so the following illustration is simply a possible scenario :

Expand|Select|Wrap|Line Numbers
  1. CartEvent  Correlation
  2. STOLEN     DISPOSED
  3. DISPOSAL   AVAILABLE
  4. DELIVERY   INSERVICE
  5. REMOVAL    AVAILABLE
  6. REPAIR     INSERVICE
  7. MISSING    DISPOSED
  8. FOUND      AVAILABLE
  9. UNKNOWN    UNKNOWN
With such a correlation indicated and stored in your table we could amend the source of the ComboBox to select only those records whose [Code_Type] = [CartEvent] and whose [Correlation] = [cboCartStatus].
Nov 18 '11 #16
mrsgwen90
37 New Member
ok, now I'm beginning to understand what you are saying...


cboCartStatus Correlation
1. InService Delivery, Repair
2. Available Removal, Found
3. Disposed Disposal
4. Unknown Missing, Stolen, Unknown
Nov 21 '11 #17
NeoPa
32,558 Recognized Expert Moderator MVP
OK. Good.

Are you going to set these simple correlations up in your table as in my illustration then? That would certainly be a more appropriate way to handle the situation. It can be done purely in code, but I would certainly advise against it. It is a small job to add the extra ([Correlation]) field to the table, and from there the code is much more straightforward.

The following SQL should then work for you :
Expand|Select|Wrap|Line Numbers
  1. SELECT DISTINCT 
  2.        [Code_Desc]
  3. FROM   [dbo_tbl_CartInfoCodes]
  4. WHERE  ([Code_Type] = 'CartEvent')
  5.   AND  ([Correlation] = Forms!MainForm!cboCartStatus)
Nov 21 '11 #18
mrsgwen90
37 New Member
is this the absolute only way to do it? This access application has a sql backend and to manipulate the table I would have to go through our database administrator which would be like pulling teeth.
Nov 21 '11 #19
mrsgwen90
37 New Member
Is there a way to maybe do a Case statement that will work with how the table is designed now?

maybe something like this:
Expand|Select|Wrap|Line Numbers
  1.  Select Case cboCartEvent
  2.   Case INSERVICE
  3.        cboCartEvent = DELIVERY, REPAIR
  4.   Case AVAILABLE
  5.        cboCartEvent = REMOVAL, FOUND
  6.   Case DISPOSED
  7.        cboCartEvent = DISPOSAL
  8.   Case UNKNOWN
  9.        cboCartEvent = MISSING, STOLEN, UNKNOWN
  10.  
  11. End Select
  12.  
just a thought.....
Nov 21 '11 #20
NeoPa
32,558 Recognized Expert Moderator MVP
MrsGwen90:
is this the absolute only way to do it?
I hear you, and No - It's just the most straightforward.

An alternative oft used in such circumstances is to create your own local table to support this functionality. It does mean that any changes made to the original source data would need to be duplicated separately (and often manually) to your shadow table.

Your extra local table would look like this (Call [tblX] whatever you want) :

Table = [tblX]
Expand|Select|Wrap|Line Numbers
  1. Field        Type
  2. CartEvent    String
  3. Correlation  String
Its contents would look like :
Expand|Select|Wrap|Line Numbers
  1. CartEvent  Correlation
  2. DELIVERY   INSERVICE
  3. DISPOSAL   DISPOSED
  4. FOUND      AVAILABLE
  5. MISSING    UNKNOWN
  6. REMOVAL    AVAILABLE
  7. REPAIR     INSERVICE
  8. STOLEN     UNKNOWN
  9. UNKNOWN    UNKNOWN
To get the most reliable linkage (IE. when the data is not up-to-date you see a problem) use the following code :
Expand|Select|Wrap|Line Numbers
  1. SELECT [Code_Desc]
  2. FROM   [dbo_tbl_CartInfoCodes]
  3. WHERE  ([Code_Type] = 'CartEvent')
  4.   AND  ([Code_Desc] In(SELECT [CartEvent]
  5.                        FROM   [tblX]
  6.                        WHERE  ([Correlation] = Forms!MainForm!cboCartStatus))
Nov 21 '11 #21
NeoPa
32,558 Recognized Expert Moderator MVP
MrsGwen90:
Is there a way to maybe do a Case statement that will work with how the table is designed now?
There is a way, but not as straightforwardly as that in Jet SQL. There are very many reasons why it wouldn't be a great idea even if the code were less complicated though.

You're designing a database. Why not take advantage of that and let Access do the complicated stuff for you. It's designed that way ;-)
Nov 21 '11 #22

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

Similar topics

25
10171
by: Lyn | last post by:
Hi, I am working on a genealogy form. The only table (so far) lists everybody in the family, one record per person. Each record has an autonum ID. The parent form (frmMainForm) displays the data in each record, which includes the ID of the father and the mother (who also have records in the table). One record per form. I have a Tab...
1
11806
by: meganrobertson22 | last post by:
Hi Everyone- I am trying to use a simple macro to set the value of a combo box on a form, and I can't get it to work. I have a macro with 2 actions: OpenForm and SetValue. I can open my form, but I can't get the macro to set the value of a combo box on the form that opens. I don't need the macro to look up any values, I just want it to...
1
2381
by: hakunamatata5254 | last post by:
Hi all, In my project of multiple forms (main form, subform1, 2 , 3 etc) (Main form is Employees, Subforms are Attendance, salary details, payment) Now i want to calculate the payment based on the salary details (Basic, Allowances etc) and the attendance (days worked and overtime hours). Overtime pay should be based on the basic only. ...
1
3088
by: lawton | last post by:
Source: this is an access 2003 question My knowledge level: reading books, internet, and trial & error; no formal training I'm trying to get a running sum of what's filtered in a subform which is ultimately driven by the results of two combo boxes: 1st combo box on main form that filters desired results for 2d combo box on sub form Main...
2
1830
by: mnms | last post by:
Hi, I'm trying to create an "overview" form. And I haven't been able to figure out how to get Access to do what I want yet. Basicly what I want, is to populate a subform based on a field selection. In other words, I have several fields like colour, shape, location etc. on my Main form. Now I want to add a subform to my unbound mainform,...
8
5163
by: NJonge01 | last post by:
Great thanks to all the helpful responses I've read! Recently using MS Access after a lengthy (7-10 years) away from the tool. I apologize for posting a question that for all intents & purposes appears to have been answered several times. Unfortunately, I've tried nearly a dozen approaches that seem to work for others on this board with similar...
2
2000
by: Rex | last post by:
I have a main form and a subform. The main form has a combo box control and the subform has a textfield. What I want to do is when the main form loads it should check the value of the combo box and if it, lets say "MZ" then the textfield in the subform must be enabled otherwise it should be remain disabled. This should be done without...
1
2655
by: daleshei | last post by:
I have a combo box with list all the queries I have on my database: Form is called: frm_qry_slct Combo box (Unbound): Combo23 RowSourceType: Table/Query RowSoource:SELECT FROM MSysObjects WHERE =5 And Like "qry_#*" ORDER BY ; Then my SubForm
1
6767
by: woodey2002 | last post by:
Hi Everyone and many thanks for your time.. I am trying to begin access and a bit of VBA i am enjoying it but I have a annoying problem I just can’t get any where on. My databse mostly includes bits of code for different examples. I have one last thing to finish. I am trying to create a search form that will allow users to select criteria from...
1
3225
by: ncsthbell | last post by:
Hello, I hope I can do a good enough job trying to explain this situation! I have inherited the maintenance for an access database and I have been requested to make a change to a form to add 2 combo boxes. I am encountering problems with getting the data value from one of the combo boxes (for divisions and groups) to be updated on the record. ...
0
7182
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...
0
7408
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. ...
1
7142
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...
0
7548
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 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...
0
5714
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...
0
3267
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
1624
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
1
825
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
488
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...

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.