Hi again Colin,
In subformSETRModels, embedded in fmSETR, we have decided we want to filter by the VDS (a five-digit code that represents a model's combination of trim level, and powertrain) instead of just year and model name. If you take a look at tblModels, you will see a column labeled VDS which contains each five digit code for every combination of model name and year. For example, a 2008 Tundra has 15 different possible VDSs, but there are 25 in the table because I needed some blanket type VDSs (the ones with asterisks) that would ignore variations in trim, bodystyle or powertrain
At a quick glance, it seems to me that you need to normalize this new information. Each VDS code may be linked to one, or many modelname -year combinations. Each model name-year combination may be linked to one or many VDS codes. To me that spells two more tables: a VDS code table and a junction table to list model name-year combinations vs VDS code id's. Once you have that, you simply set the row source for the VDS combo box to query the junction table using the model name-year combination (ModelID) that you have selected in the sbfmSETRModels form as a criteria.
Now, if more than one vds code needs to be assigned to a model name-year combination in the SETR, then you need to create a third table to handle the one to many nature of that relationship. This would further necessitate that you need to use a nested subform on sbfmSETRModels to contain the VDS codes for that model name-year combination in that SETR.
Also, the next subform, subformSETRModelsParts, I would like to be able to enter part numbers in here directly, as opposed to putting them in through another form. Is this as simple as creating a text box, and setting its control source to the corresponding field in the Parts table? Or will I need a query to ensure the table also gets the ModelID (year and name) to record it?
A form can only be bound one recordset (table or query) at a time so you cannot enter directly into the parts table (tblParts) from a form that is already bound to a different table (tblSETRModelParts).
However, you can use a variety of ways to add items to the Parts table from your subformSETRModelsParts form. One way would be to use the Not In List event of the combo box which is bound to your PartID field. Or, add a command button to open a popup form in data entry mode, which is bound to your tblParts, then requery the combo after the popup closes.
You will likely need two new forms to handle this task. One to add existing parts to tblModelParts for various model name-year combinations, another to add a totoally new part number to the db (tblParts).
In your case, once a user had a added a brand new part to the db, you will also want to consider prompting the user to also list all the model-year combinations that the new part is used in (to go in tblModelParts) so that the combo box knows to include this part number in the list (since it uses the information in the tblModelParts to filter out any parts that are not associated with the selected model name-year). This is one of those areas I told you about that still needed attending to when I gave you the example db (you did say you wanted to do some of this after all). I have already showed you how to open a popup form for adding new engineers and locations etc.
When the Part # is recorded, it takes the ModelID as well, but there are cases where one part number might apply to several models. I can't estimate how often a part number might be duplicated within an SETR, but but do you think it would make more sense to allow duplicates in the part-number field? or create a junction table between the model and parts tables?
There is already a junction table between the model and parts tables. It's called tblModelParts.
You have to remember that there are three tables here. tblParts which lists individual components of vehicles. tblModelParts which stores information about which parts (PartID) belong with which model name-year combination (ModelID). And the third is tblSETRModelParts which your subform is bound to. This stores information about which parts (PartID) from which model name-year combination (ModelID) are requested by this SETR (SETRID).
No matter how you achieve the data entry, you must store the individual PartID for each ModelID in the SETR as a line in that table. You can add each one manually, or you can create a button to 'Add all Parts' for that ModelID
to run some SQL to append the data en-mass (using the information in tblModelParts to provide the appropriate list). Up to you. Regardless, the data structure should never be de-normalized like you're contemplating.
I was starting to create a new form for creating SETRs, its called frmSETR, if you want to take a look at the direction I was going. I realize there are some things that won't work out, like using list boxes for multiple selection (each line can only have one model, and one model year), etc.
List boxes are not my friend. Have never used one except on the menu of your db (for self education purposes). You can bind a multi-select listbox to a field because you can only store one piece of information in a table. You can, however, use an unbound mutliselect listbox to append rows to a table using vba to create the right SQL. However, I'm not going to be much use to you there since I'm not real familiar with them as I find subforms and command buttons more appropriate for that in most instances. In your case, each modelname-year combination has, potentially, a separate list of parts that might be requested within a SETR. That means the multi-select listbox approach is going to be highly problematic. Not saying someone couldn't make it work...but it's more work than I'd undertake.
As for the form, well, you have three 'boxes' for part numbers. What if there's 10 parts requested for your 2008 Tundra and 7 different parts requested for the 2005 Camry? Three boxes won't work. And three boxes on a form indicates three fields in the underlaying recordsource. You're forgetting the cardinal rule of one-to-many relationships and forms: you need a subform bound to a related table to handle that task.
I keep getting the impression you're looking for shortcuts for data entry. Something like wanting to select several models at once, and several parts at once. But the reality I got from your earlier posts is that, because the parts requested might differ for model name-year combinations within setr, you can't adopt such a simplistic data entry convention because the data model is far more complex. Now, you can automate some of that data entry as I suggested above, but the underlaying data model requires much more of you than your form design would allow. But instead of trying to force several items into one box, you should think about using command buttons to run SQL to append records using information in tblModelParts as a guide. Then allow the user to delete any appened records that they don't want.
Further, I'm not sure what the purpose of the line number command button is. Line numbers are assigned automatically during the export process from the main form. What are you trying to do with this button here?