Solved

Access subform filter data from parent

Posted on 2013-11-04
11
849 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

726 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