?
Solved

Access subform filter data from parent

Posted on 2013-11-04
11
Medium Priority
?
883 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
Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

 
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 2000 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

Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

Question has a verified solution.

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

Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
If you’re using QODBC to update QuickBooks data from Microsoft® Access but Access is not showing the updated data, you could have set up QODBC incorrectly.
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…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

850 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