UmmNick
07-09-2008, 08:13 PM
I don't know what the proper word would be, if u have a form on a form is that considered a MainForm with a SubForm or an EmbeddedForm? Not much on the technical wording of any applicaiton for that matter.
Anyhow, I have a ComboBox on the MainForm that updates the recordsource via a query. That works fine.
The EmbeddedForm is also based on a query. I want to be able to update the query of the MainForm using data from both the MainForm and the EmbeddedForm. Not sure how to write the [SELECT] statment to use the data from both.
MainForm
Example: [SELECT] Employees.* FROM Employees WHERE Location = ComboBox1
EmbededForm
Example: [SELECT] Skills.Skill List, Skills.Employee ID FROM Skills Where Employee ID = Employees.Employee ID
Grrr, I don't have access to my Database atm, the above may not be exactly right, but it's close enough to get the idea.
Obviously Wrong (Hmm)
Somewhat of an Example: [SELECT] Employess.* FROM Employees WHERE Location = ComboBox1 and Skills.* FROM Skills WHERE Skills List = ComboBox2
Basically, I have the MainForm showing only Employees from a particular location and the EbeddedForm shows their Skills. I want to be able to have the MainForm show only Employees from a particular location (ComboBox1) who have a particular skill (ComboBox2).
Any help would be greatly appreciated, will update my exact query info in the morning.
Thanks,
Nick
namliam
07-09-2008, 11:35 PM
SubForm is the general word for a form in a form.
For the main form you can use
Select...from...where ... = Forms("FormName").Combobox
To run your query... just enter that into the RowSource.
For the subform, you can just use the default linking ability of the subform to the main form.
And use Select... from ... in your rowsource without any reference to your mainform.
In the properties of the Subform you can set the linking criteria from mainform to subform.
UmmNick
07-10-2008, 04:24 AM
SubForm is the general word for a form in a form.
For the main form you can use
Select...from...where ... = Forms("FormName").Combobox
To run your query... just enter that into the RowSource.
For the subform, you can just use the default linking ability of the subform to the main form.
And use Select... from ... in your rowsource without any reference to your mainform.
In the properties of the Subform you can set the linking criteria from mainform to subform.
Headed to the office shortly, will give it a shot but don't see how that will filter the queery on the MainForm using the SubForm data. Both ComboBoxs are one the MainForm. :confused:
namliam
07-10-2008, 05:20 AM
Ah but then you are looking for some more complex filter.... query thing.
You cannot use a sub-form to filter a main form....
If you want to filter your main form to only people that have a certain skill you are still stuck in setting the recordsource of the mainform without ever touching the subform.
Any filter you put to the subform will only result in limiting the subform not the main one.
You are looking for something like:
Select...from...where ... = Forms("FormName").Combobox
or EmployeeKey in (select employeeKey from Skills where skill = Forms("FormName").Combobox
Note:
1) I just noticed you are not using prefixes for your tables. You really should use a naming convention where you prefix all tables by tbl.
2) A combobox by its nature can only select 1 value if you want to select more values you have to use a listbox. This solution is geared for a combobox and will not work with a multi-select listbox.
3) If you select multiple skills this will select all employees that have one or more of these skills (or) . If you want only employees that all these skills (and) then you have to use something else)
UmmNick
07-10-2008, 08:40 AM
Basically I want something like the follow but don't know how to write it or even if it's possible:
Select Employees.* FROM tblEmployees WHERE tblSkills.[Skill] = Form("Employees").ComboBox
A querry that uses two tables, tblEmployees and tblSkills?? I've heard it mentioned but haven't seen anything in particular on doing it.
namliam
07-10-2008, 10:00 AM
Ah but then you are looking for some more complex filter.... query thing.
You cannot use a sub-form to filter a main form....
If you want to filter your main form to only people that have a certain skill you are still stuck in setting the recordsource of the mainform without ever touching the subform.
Any filter you put to the subform will only result in limiting the subform not the main one.
You are looking for something like:
Select...from...where ... = Forms("FormName").Combobox
or EmployeeKey in (select employeeKey from Skills where skill = Forms("FormName").Combobox
Note:
1) I just noticed you are not using prefixes for your tables. You really should use a naming convention where you prefix all tables by tbl.
2) A combobox by its nature can only select 1 value if you want to select more values you have to use a listbox. This solution is geared for a combobox and will not work with a multi-select listbox.
3) If you select multiple skills this will select all employees that have one or more of these skills (or) . If you want only employees that all these skills (and) then you have to use something else)
Read the post again... I think that answer is in here :)
UmmNick
07-10-2008, 11:40 AM
...maybe but sometimes I can seem really dense and overlook the obvious, that I will not deny but umm, the answer seems kind of vague as I am not familar with writting a queery to filter a forms data based on two diff tables. Anyhow, here's my code for handling two diff ComboBoxes. I'll put some comments in the explain and explain what it's doing.
Private Sub Combo96_AfterUpdate()
' Find the records with data that matches the follow ComboBoxs
Dim strSQL As String
' * Basically, if both boxes are set to "All", then give me all the records.
If Combo96 = "All" And Combo92 = "All" Then
strSQL = "SELECT Employees.* " & _
"FROM Employees "
Me.RecordSource = strSQL
' * If only Combo96 is "All" then filter on Combo92 setting
ElseIf Combo96 = "All" Then
strSQL = "SELECT Employees.*, Employees.Site " & _
"FROM Employees " & _
"WHERE Employees.Site = " & Chr(34) & Combo92 & Chr(34)
Me.RecordSource = strSQL
'*** Else Just return Records with a specific Responsibility
'*** There are multiple responsiblities per Employee
'*** Emp ID and Res List ID are both numbers in table (responsibilities)
'*** Res List ID is related to another table (Resp List)
'*** where each Res List ID is the key to a particluar responsiblity
'*** what I have below just kicks me out on the recordsource
'*** saying you canceled the previous operation?
'*** I figure the main form needs tblEmployees as the recordsource
'*** since all the data is from the Employee Table.
Else
strSQL = "SELECT Responsibilities.[Employee ID],
Responsibilities.[Responsibility List ID] " & _
"FROM [Responsibilities] " & _
"WHERE [Responsibilities].
[Responsibility List ID] = " & Chr(34) & Combo96 & Chr(34)
Me.RecordSource = strSQL
End If
End Sub
P.S. I know there are other ElseIf options unaccounted for, I'll be happy right now just getting the MainForm filtered dependent on the Employees Table and the Responsibilities Table.
More help would also be appreciated. :)
namliam
07-10-2008, 11:55 PM
I hope your code is properly indented, this is unreadable!
And if it is, please add "[ code ]" at the start and " [ /code ]" at the end to keep the indentations.... remove the spaces inside the brackets tho, to make it work.
Also using Combo96 and Combo92 as names for your comboboxes IS NOT good practice. Rename your objects to something meaningfull! Combo92 should be called something like cboEmployeeSite (or something simular)
Another thing is, please dont use spaces in any names... Again not good practice. This goes hand in hand with a naming convention I meantioned earlier to use tbl in front of your table names.
Yet a fourth thing:
strSQL = "SELECT Employees.*, Employees.Site " & _
"FROM Employees " & _
"WHERE Employees.Site = " & Chr(34) & Combo92 & Chr(34)
Me.RecordSource = strSQL[/quote]
If you are select Employees.* there is no need to add Employees.Site seperatly, even tho this is explicitly mentioned in the were. * means ALL.
Also (as a fifth remark?) you have "Me.RecordSource = strSQL" multiple times, you should only need it multiple times just one time at the end of the Sub
Now for the real problem at hand...To filter your main form on the skills you need to do something like:
[code]
Select...
from...
where EmployeeKey in (select employeeKey
from Skills
where skill = Me.Combobox )
Again this works for a combo box, not a multi select listbox.