 |
| Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Access section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

June 6th, 2004, 04:27 PM
|
|
Authorized User
|
|
Join Date: Apr 2004
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
using a query to filter forms
Hi, can someone help me. I am trying to use the results of a query to filter a form. ie:
Private Sub Command5_Click()
On Error GoTo Err_Command5_Click
Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "CandidatesMain"
stLinkCriteria = "[CandidateID]=[qual]![CandidateID]"
DoCmd.OpenForm stDocName, acNormal, , stLinkCriteria, acFormPropertySettings, acWindowNormal
Exit_Command5_Click:
Exit Sub
Err_Command5_Click:
MsgBox Err.Description
Resume Exit_Command5_Click
End Sub
The query [qual] finds the candidates that have the qualifications selected in the combo box 'Command5'. I then want to open the candidates form [CandidatesMain]filtered to only show these candidates.
Is this possible? if so, what am I doing wrong?
any help would be greatly appreciated.
thanks
liz
|
|

June 8th, 2004, 12:54 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 129
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi Liz,
You say Command5 is a combo box. But you have Command5_Click() which suggests a button. Your problem looks like something to do with using variables in your string.
Let's look at something simpler. Why not build your CandidatesMain form recordsource (use the query builder) to just choose records where qual is equal to Command5 (if, of course, Command5 really is a combo box). In the quals column of your recordsource query just put =Forms!CandidatesMain!Command5 or maybe even Me!Command5
Hope this helps.
Clive Astley
|
|

June 9th, 2004, 04:53 AM
|
|
Authorized User
|
|
Join Date: Apr 2004
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi Clive
Thanks for your response. To clarify, Command5 is a button (sorry it was late the other night!!) set to open the CandidatesMain form based on the results of the query [qual]. The query [qual] links the CandidatesID to the candidateâs qualifications records and are then filtered in response to the selection made in the combo box [text2]. The candidates qualifications records are not part of the recordsouce of the CandidatesMain form, they are part of a subform linked to the CandidatesMain form (one to many relationship
So to simplify, I want to filter a form based on a field in one of its subforms. How is the best way to do this?
regards
liz
|
|

June 9th, 2004, 03:02 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 129
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
So the query [quals] contains a list of CandidatesIDs that you want the CandidatesMain form based on? Yes?
Create a new query. Use query [quals] as one of its "tables". Use the Candidates table as the other table in the query. If not already linked, link query [quals] and Candidates on CandidatesID. Use this new query as the recordsource of CandidatesMain form.
This seems a bit messy. Why can't you use [quals] as part of the CandidatesMain form recordsource? But the important thing is to get it working. Then you can tidy it up.
Hope this helps
Clive Astley
|
|

June 10th, 2004, 04:59 AM
|
|
Authorized User
|
|
Join Date: Apr 2004
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi Clive
Some more detail:
The database is a recruitment database. The form CandidatesMain is the main input form for all candidates details and is sourced from the main table [Candidates]. The form then has a number of subforms showing the candidates experience, qualifications, school history, skills etc. The user needs to be able to find a short list of candidates based on multiple criteria. So I am setting up a dialog box that will filter the main form based on whichever criteria they need. ie: they may be looking for a candidate with a certain experience or they could be looking for someone with a certain qualification etc. Because there is so much info on each candidate, rather than show the results of the search in a report (the report would be huge), I would rather show the results by filtering the candidates main form so that the user can then scroll through the potential candidates and see all their info. So the candidates main form will have a dual purpose - to enter and view details for all candidates - and secondly to view details of selected candidates based on the filter.
What do you think?
regards
liz
|
|

June 10th, 2004, 06:47 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
|
|
Your problem is two-fold. If you want to get the results for the query then:
stDocName = "CandidatesMain"
is wrong. You're addressing the table, not the query. You should have:
stDocName = "qual"
Then...
stLinkCriteria = "[CandidateID]=[qual]![CandidateID]"
would be:
stLinkCriteria = "[CandidateID] = '" & Me.txtCandidateID & "'"
Where you're comparing it to a textbox in your form, e.g. called txtCandidateID.
Greg Serrano
Michigan Dept. of Environmental Quality, Air Quality Division
|
|

June 10th, 2004, 06:50 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
|
|
Whoops... I forgot to mention, that if you want to open the form based on the query then the stDocName is correct as "CandidatesMain" after all. It's the form's control source that must be the query's name. But the criteria setting I mentioned still holds.
Greg Serrano
Michigan Dept. of Environmental Quality, Air Quality Division
|
|
 |