|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
combobox in subform dependent on main form value
Hi all,
I have a main form called mainform and there is subform1 in it. In subform1, there is subform2. The following is an illustration: Mainform - caseID (pk) subform1 - scenarioID (pk) , caseID subform2 - outcomeID (pk), scenarioID, requirementID (this is a combo box listing all the requirements for caseID from Mainform.) The requirementID is from a requirement lookup table with the fields (requirementID, requirementText, caseID). In subform2, I want the requirementID combo box to list only requirements that has the same caseID as on the mainform. What I've done is on subform2, I created a combobox RequirementList and added the following code: Code:
Private Sub RequirementList_GotFocus() Dim strSQL As String 'Develop SQL statement for row source of Project Number combo box: strSQL = "SELECT [tblRequirements].[rqmtid], [tblRequirements].[rqmt] " & _ "FROM tblRequirements WHERE " & _ "[tblRequirements].[usecaseid] = 45" 'Finish establishing combo box properties: RequirementList.RowSource = strSQL RequirementList.RowSourceType = "Table/Query" RequirementList.BoundColumn = 1 End Sub What's happening is this code works for 3 records and crashes access. What's wrong with this? Should I place this at another event? Any help is grateful. Anthony |
|
#2
|
|||
|
|||
|
Hi,
I may just confuse you, but it seems that if you have correct one to many relationships in your database and that the subforms are correctly linking on the primary to foreign keys, wouldn't the requirements (RequirementID, RequirementText) pop up for the CaseID and ScenarioID automatically? Is this an entry or edit form or both? If you have a one to many relationship established for CaseID to ScenarioID, then a one to many relationship from ScenarioID to OutcomeID, I think it should work. The CaseID should not have to be saved with the RequirementID Lookup Table. Now in your form creation, in subform 2, your default view should be continuous forms, so that multiple requirements can be entered or seen for the CaseID that is currently selected. I hope I have helped some, BetsyBean |
|
#3
|
|||
|
|||
|
Yes, if you set up the relationships, and the form and combobox recordsources correctly, you shouldn't need to do queries in code. Thats the nice thing about subforms.
Also since your code is not dynamic, you could just put each of those lines into the controls themselves. |
![]() |
| Viewing: Dev Articles Community Forums > Databases > Microsoft Access Development > combobox in subform dependent on main form value |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|