Solved

Access subform filter data from parent

Posted on 2013-11-04
11
845 Views
Last Modified: 2013-11-07
I have an application that starts with a Main form. When the user selects a job and clicks a button this code executes
   
    stLinkCriteria = "[Job#]=" & Me![lboxJobList]
    DoCmd.OpenForm stDocName, , , stLinkCriteria

this works and the form/subform display correctly

The problem is that access appears to load the entire table for the subform

The subform recordsource is just a simple select

select * from jobdetails

How can I convert this to a query with a where clause and then set the parameter before loading?
0
Comment
Question by:JonMny
  • 4
  • 4
  • 2
  • +1
11 Comments
 
LVL 10

Expert Comment

by:etech0
ID: 39622549
If the form and subform both show the correct record, I don't see what the problem is...

By subform, do you mean that is embedded in the main form? Which form does the button open?
0
 
LVL 9

Author Comment

by:JonMny
ID: 39622560
it's a performance problem.

one form opens a second. The second form has the subform
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 39622573
<The second form has the subform >

on this second form, did you set the Master/Child Link fields property of the subform?
0
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 
LVL 9

Author Comment

by:JonMny
ID: 39622613
yes those are set to the job#
0
 
LVL 10

Expert Comment

by:etech0
ID: 39622620
Assuming that you have the ability to change records from the parent form, your setup is  really the best setup for what you want. We could set it so that the subform's recordsource was that one record, but then it would have to requery each time you change records, which would take more time.
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 39622641
the problem here is, the subform is loaded first before the main form, so when you apply the filter to the main form from the command  "docmd.openform" the subform is already loaded.. so add this code in the load event of the main form

private sub form_load()



me.subformcontrolName.requery

end sub
0
 
LVL 9

Author Comment

by:JonMny
ID: 39622682
the table is linked to a SQL Azure database. It takes about 2 min to open the form. So really needs to load on demand
0
 
LVL 10

Expert Comment

by:etech0
ID: 39622694
Do you ever use the parent form to change records?
0
 
LVL 9

Author Comment

by:JonMny
ID: 39622699
no they have to go back to the main form to do that.
0
 
LVL 10

Expert Comment

by:etech0
ID: 39622758
What's the recordsource of the parent form?
0
 
LVL 61

Accepted Solution

by:
mbizup earned 500 total points
ID: 39623836
If you wamt to load records on demand,  leave your main and subform recordsources blank in their property sheets (Keep the master/child links intact), and set the recordsources through code in their open events, loading just the records specified by the first form.

In the Subform Open Event:

Dim strSQL as string
Dim strCriteria as string

StrSQL = "SELECT * FROM jobdetails " 

strCriteria = NZ(Forms!YourFirstFormName.lboxJobList,"")
If strCriteria <> "" Then  strCriteria = "WHERE [job#] = " & strCriteria

Me.Recordsource =  strSQL  & strCriteria

Open in new window



And in the main form Open event (adjust according to your actual mainform query, as needed):


Dim strSQL as string
Dim strCriteria as string

StrSQL = "SELECT * FROM jobMain " 

strCriteria = NZ(Forms!YourFirstFormName.lboxJobList,"")
If strCriteria <> "" Then  strCriteria = "WHERE [job#] = " & strCriteria

Me.Recordsource =  strSQL  & strCriteria

Open in new window

0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question