Solved

Access subform filter data from parent

Posted on 2013-11-04
11
836 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
Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

 
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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Top 1 of each supplier 55 57
Access on Mouse move 5 35
Reference Controls on subforms 7 28
Using LPR to print to IP Barcode printers VBA MS Access 11 17
Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

810 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