Solved

Access subform filter data from parent

Posted on 2013-11-04
11
825 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
Comment Utility
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
Comment Utility
it's a performance problem.

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

Expert Comment

by:Rey Obrero
Comment Utility
<The second form has the subform >

on this second form, did you set the Master/Child Link fields property of the subform?
0
 
LVL 9

Author Comment

by:JonMny
Comment Utility
yes those are set to the job#
0
 
LVL 10

Expert Comment

by:etech0
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 119

Expert Comment

by:Rey Obrero
Comment Utility
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
Comment Utility
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
Comment Utility
Do you ever use the parent form to change records?
0
 
LVL 9

Author Comment

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

Expert Comment

by:etech0
Comment Utility
What's the recordsource of the parent form?
0
 
LVL 61

Accepted Solution

by:
mbizup earned 500 total points
Comment Utility
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

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…
In Debugging – Part 1, you learned the basics of the debugging process. You learned how to avoid bugs, as well as how to utilize the Immediate window in the debugging process. This article takes things to the next level by showing you how you can us…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

744 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now