473,385 Members | 1,893 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Displaying only certain records in a subform

In subFormC, I would like to display only those records that have TrialDate
and CompanyCode equal to TrialDate and CompanyCode in subFormB.

Can somebody please help me?

Thanks

Tim
Nov 13 '05 #1
3 1891
You can base the recordsource of subformC on a query with a query string
like this:

Dim strSql As String

strSql = "Select * from sourceTbl Where (TrialDate in (Select TrialDate
from subformBsourcetbl Group By TrialDate )) And (CompanyCode in (Select
CompanyCode From subformBsourcetbl Group By CompanyCode ))"

Me.subFormC.Form.RecordSource = strSql

Me.Requery
Me.Refresh

The Group By in the sub queries of the sourceTable of subformb groups
Trialdate to Distinct TrialDates. Like say you had 10 dates of 1/1/01
and 20 dates of 2/1/01 and 30 dates of 3/1/01, the group by gives you 3
dates, 1/1/01, 2/1/01, and 3/1/01. The same for companycode.

HTH
Rich

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 13 '05 #2
Rich,
I tried the code that you wrote below, but I got the following error
whenever I tried to include the Dim statement
" Invalid SQL Statement; Expected 'Delete', 'Insert', 'Procedure',
'Select', or 'Update'

Here is my code now in a simplified version

SELECT *
FROM TblRunSpecs
WHERE TblRunSpecs.TrialDate=TblTrialsMainData.TrialDate And
TblRunSpecs.CompanyKey=TblTrialsMainData.CompanyKe y;

This code DOES produces the results I'm looking for except that I have to
manually enter the parameters

I know that I need the Dim statement at the beginning, and the RecordSource
statement at the end, but I can't get around the error.

Can you help?

Thanks...Tim

"Rich P" <rp*****@aol.com> wrote in message
news:41**********************@news.newsgroups.ws.. .
You can base the recordsource of subformC on a query with a query string
like this:

Dim strSql As String

strSql = "Select * from sourceTbl Where (TrialDate in (Select TrialDate
from subformBsourcetbl Group By TrialDate )) And (CompanyCode in (Select
CompanyCode From subformBsourcetbl Group By CompanyCode ))"

Me.subFormC.Form.RecordSource = strSql

Me.Requery
Me.Refresh

The Group By in the sub queries of the sourceTable of subformb groups
Trialdate to Distinct TrialDates. Like say you had 10 dates of 1/1/01
and 20 dates of 2/1/01 and 30 dates of 3/1/01, the group by gives you 3
dates, 1/1/01, 2/1/01, and 3/1/01. The same for companycode.

HTH
Rich

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 13 '05 #3
If TblTrialsMainData is the source table for subformB then the following
sql string should work:

strSql = "Select * from TblRunSpecs Where _
& "(TrialDate In (Select TrialDate " _
& "From TblTrialsMainData Group By TrialDate)) And " _
& "(CompanyKey In (Select CompanyKey From " _
& "TblTrialsMainData Group By CompanyKey))"

This code assumes that TblRunSpecs contains a bulk of data and you want
to retrieve a subset of records from TblRunSpecs where the records
contain TrialDates and CompanyKey the same as the TrialDates and
CompanyKey from TblTrialsMainData

Again, the two subqueries in the sql string above will retrieve all the
unique TrialDates from TblTrialsMainData and all the unique CompanyKeys
from TblTrialsMainData.

Before implementing this sql into your project you should test it as
follows:

Sub testSql()
Dim strSql As String, RS AS DAO.Recordset

strSql = "Select * from TblRunSpecs Where _
& "(TrialDate In (Select TrialDate " _
& "From TblTrialsMainData Group By TrialDate)) And " _
& "(CompanyKey In (Select CompanyKey From " _
& "TblTrialsMainData Group By CompanyKey))"

Set RS = CurrentDB.OpenRecordset(strSql)
RS.MoveLast
Msgbox RS.RecordCount
End Sub

In your hardcoded query, the number of records you get from that should
match RS.RecordCount.

Rich

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 13 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Matt K. | last post by:
Hi there, I have a form in an Access project that contains a subform which displays the results of a query of the style "select * from where = #a certain date#". In the main part of the form...
3
by: Robin S. | last post by:
I tried to ask this question several days ago, but I didn't explain my application correctly. Basically I want to have one record from table "A" and I want to display, say, 5 records from table...
0
by: Ellen Manning | last post by:
I've got an A2K form with a subform based on a query. This query has a checkbox and an amount field and returns records if checkbox is checked. I Dsum the amount field and display on the main...
5
by: Robert | last post by:
Hello Accessors I have some reports created in Access that are very good for what they do. However, it seems to me that when you are displaying information you don't need to print out that a...
5
by: tdmailbox | last post by:
I have a form with a child form. In the child form there is a list of names that can grow quite large. On the parent form I want to display the first name from the child form. I set up a test...
9
by: Susan Bricker | last post by:
Greetings. I am having trouble populating text data that represents data in my table. Here's the setup: There is a People Table (name, address, phone, ...) peopleID = autonumber key There...
4
by: Krzysztof Bartosiewicz | last post by:
Hi! I haven't been using Access for a very long time and I forgot everything :) I will be very greatful for help since I have been fighting with this problem for a few hours... I have three...
3
by: Typehigh | last post by:
I am a good programmer, but this one stumps me! I have a form with a continuous subform. The continuous subform contains records of data and may reach a depth of 1000's of entities. I have...
2
by: Mike | last post by:
I have a parent form with two subforms on it. Each subform lists certain records and then totals up one of the fieldsd. The parent form then totals up the two text boxes. The problem is that if...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.