Solved

How populate form field with values from sub-form

Posted on 2014-12-10
6
198 Views
Last Modified: 2014-12-10
I have a form and a sub-form.  On the main form is a field named "txtClasses".

On the sub-form (datasheet view) is a field named "Class".  

When the main form is opened I want the field "txtClasses" to be populated with the UNIQUE values from the subform field "Class" separated by commas and a space.

So using this example of the sub-form...

Classes Example
I would want the field on the main form to read "Football, Baseball, Basketball, Hockey"

How can this be done?  

--Steve
0
Comment
Question by:SteveL13
6 Comments
 
LVL 22

Expert Comment

by:rspahitz
ID: 40491770
How about building a query on a hidden combobox with the data source "Select Distinct Class From {table}" then run a quick command to iterate through the entries and add commas after them to put into the text box?
0
 
LVL 34

Assisted Solution

by:PatHartman
PatHartman earned 250 total points
ID: 40491775
Create a query that selects DISTINCT just the Classes field for the ID of the current record.
Select DISTINCT Class
From YourTable
Order by Class
Where PrimaryKey = Forms!yourform!PK;

Then in the current event of the form, open a recordset and loop through it concatenating the values from the Class field.
0
 
LVL 74

Accepted Solution

by:
Jeffrey Coachman earned 250 total points
ID: 40491870
0
Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

 

Author Comment

by:SteveL13
ID: 40492210
Pat,

I have the query created and it is giving me the distinct values.  But I don't know how to:

"Then in the current event of the form, open a recordset and loop through it concatenating the values from the Class field. "

What would the code be to do that?
0
 
LVL 34

Expert Comment

by:PatHartman
ID: 40492242
Jeff posted a link to a function that shows you how to do the concatenation.
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 40492801
Yes, Pat
I think Patrick's function is one of the most popular Articles ever published here...

But like you, I sometimes still loop in case I have to check for something at each record...
...and sometimes just because it is fun...
;-)

Jeff
0

Featured Post

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Join & Write a Comment

Today's users almost expect this to happen in all search boxes. After all, if their favourite search engine juggles with tens of thousand keywords while they type, and suggests matching phrases on the fly, why shouldn't they expect the same from you…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
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…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …

743 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

12 Experts available now in Live!

Get 1:1 Help Now