Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old June 6th, 2004, 04:27 PM
Authorized User
 
Join Date: Apr 2004
Location: Cape Town, , South Africa.
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to lizhaskin
Default 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


Reply With Quote
  #2 (permalink)  
Old June 8th, 2004, 12:54 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Norwich, Norfolk, United Kingdom.
Posts: 129
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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
Reply With Quote
  #3 (permalink)  
Old June 9th, 2004, 04:53 AM
Authorized User
 
Join Date: Apr 2004
Location: Cape Town, , South Africa.
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to lizhaskin
Default

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


Reply With Quote
  #4 (permalink)  
Old June 9th, 2004, 03:02 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Norwich, Norfolk, United Kingdom.
Posts: 129
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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
Reply With Quote
  #5 (permalink)  
Old June 10th, 2004, 04:59 AM
Authorized User
 
Join Date: Apr 2004
Location: Cape Town, , South Africa.
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to lizhaskin
Default

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


Reply With Quote
  #6 (permalink)  
Old June 10th, 2004, 06:47 AM
Friend of Wrox
Points: 4,007, Level: 26
Points: 4,007, Level: 26 Points: 4,007, Level: 26 Points: 4,007, Level: 26
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Lansing, Michigan, USA.
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
Send a message via ICQ to SerranoG Send a message via AIM to SerranoG
Default

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
Reply With Quote
  #7 (permalink)  
Old June 10th, 2004, 06:50 AM
Friend of Wrox
Points: 4,007, Level: 26
Points: 4,007, Level: 26 Points: 4,007, Level: 26 Points: 4,007, Level: 26
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Lansing, Michigan, USA.
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
Send a message via ICQ to SerranoG Send a message via AIM to SerranoG
Default

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
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Trying to do a sql web query/filter u2clone ASP.NET 2.0 Basics 15 July 21st, 2007 08:49 AM
Help for Select SQL Query with date filter pushpa SQL Server DTS 0 February 6th, 2007 10:06 AM
Add Filter to a query using VB marcin2k Access VBA 2 March 20th, 2005 07:03 AM



All times are GMT -4. The time now is 02:42 AM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.