473,668 Members | 2,654 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1900
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 subformBsourcet bl Group By TrialDate )) And (CompanyCode in (Select
CompanyCode From subformBsourcet bl Group By CompanyCode ))"

Me.subFormC.For m.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.Tri alDate=TblTrial sMainData.Trial Date And
TblRunSpecs.Com panyKey=TblTria lsMainData.Comp anyKey;

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.co m> 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 subformBsourcet bl Group By TrialDate )) And (CompanyCode in (Select
CompanyCode From subformBsourcet bl Group By CompanyCode ))"

Me.subFormC.For m.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 TblTrialsMainDa ta is the source table for subformB then the following
sql string should work:

strSql = "Select * from TblRunSpecs Where _
& "(TrialDate In (Select TrialDate " _
& "From TblTrialsMainDa ta Group By TrialDate)) And " _
& "(CompanyKe y In (Select CompanyKey From " _
& "TblTrialsMainD ata 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 TblTrialsMainDa ta

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

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 TblTrialsMainDa ta Group By TrialDate)) And " _
& "(CompanyKe y In (Select CompanyKey From " _
& "TblTrialsMainD ata Group By CompanyKey))"

Set RS = CurrentDB.OpenR ecordset(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
4072
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 the user can change the date, which will force a requery in the subform to bring up records from the date selected. My question is this... The query in the subform is a very simple one, with only three fields being returned. In the interest of...
3
3500
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 "B" which are specified by the one record from table "A"... And all on the same form. I do not want to use a subform. The record fields from table "B" must be displayed in text boxes with the record fields from the single record from table "A". ...
0
1950
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 form. If the user unchecks the box, I want the corresponding amount subtracted from the total. If they recheck the box, the amount is to be added. I want all records to appear on the subform even after unchecking them. This works fine...except......
5
2217
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 printer-friendly report is not the best way to go. So, I tried converting one of my Access reports to an Access form. I selected the continuous view to allow displaying multple records but when I went to define my sorting and grouping there was none...
5
5249
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 box that is populated with the code =subfrm_media_review_sec_party.Form!first_name & " " & subfrm_media_review_sec_party.Form!last_name It works except that when I flip through the names it populates the parent form with the name of what ever...
9
2332
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 is a Judge Table (information about judges) judgeID = autonumber key
4
3647
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 tables: Medicines (ID_Medicine, ID_MedicineGroup, MedicineName), MedicineGroups (ID_MedicineGroup, MedicineGroupName) and Treatment (ID_MEDICINE, ID_CONSULT, ID_COMMENT). After the user chooses appropraite MedicineGroup and later Medicine from...
3
15393
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 created a search button on my form and it does its job quite well. It presents the user with an inputbox, prompting for the string to search. Then the code returns with a record number of the record which contains the string. Here's the problem. I...
2
3767
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 there are no records for one of the subform's query, then I get an error (obviously you can't add a value from a text box if it does not exist...): Subform 1: ItemX 10 ItemY 5
0
8462
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8893
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8656
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7401
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6209
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5681
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4205
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4380
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2791
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.