473,756 Members | 1,810 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

populating textfield from multiple records

Hi,

I'm trying to make a calculated text field in a query where the textvalue is
being populated from multiple records.
I already use a VBA function to loop through records and concatenate the
text. It works but the performance is really bad. I'm looking for a solution
in plane SQL, so the looping is done by joining tables. I can't get it to
work....
tblPersons
Persid name
------ ------
1 Dck
2 Peter
3 John
4 Paul
5 Oliver

tblHobbies
Persid Hobby
------ -------
1 Cars
1 Fishing
1 Movies
1 Horses
2 Cars
2 Music
3 Golf
3 Cars
3 Hunting
4 Cooking
5 Cars
5 Music

in the query i like to have the following data presented in two fields.

Name Hobbies
------ ---------
Dick Cars, Fishing, Movies, Horses
Peter Cars, Music
John Golf, Cars, Hunting
Paul Cooking
Oliver Cars, Music

I almost thought i had the solution by using GROUP BY and EXPRESSION in a
total query where a VBA function is called and populates the strings through
a STATIC string variable and STATIC long recordid. But unfortunatly it
didn't work well, got problems with initializing STATIC vars (Also in
genereal it seems that during debugging a function called from a running
query doesnot always return the expected results, while in normal mode the
query will run fine).

Any help would be gratefull
Thanks!
Nov 12 '05 #1
3 5619
Don't think pure SQL will do it. You have to use code. There's code for it here:

http://www.mvps.org/access/modules/mdl0004.htm

"Return a concatenated list of sub-record values"
Nov 12 '05 #2
Hi,

I still don't know if it can be done with pure SQL, but i got it working
without VBA code which loops through records. (Not to mention the time lost
for opening and closing the recordset.)

The trick is using two queries and a bit of VBA code. It works faster than
looping through records in VBA.

1. The base query GROUPS some Recordkey and GROUPS the Textfield you want to
populate. In a 3th column a calculated textfield as EXPRESSION calls a
public function fnPopulateTextf ield which takes to params (Recordkey and
Textfield).

RecID
GROUP BY

Textfield
GROUP BY

PopulatedText: fnPopulateTextf ield([RecID];[Textfield])
EXPRESSION

The second column is needed because without it the query does not recognizes
that Textfield is part of a statistic function! The side effect is that it
will group on every Textfield, but the final query will correct this!

2. The finishing query based on the above query GROUPS again on the
Recordkey and takes the LAST record of the calculated populated textfield.

RecID
GROUP BY

PopulatedText
LAST

3. The function fnPopulateTextf ield uses two STATIC vars (long and string).
every time it sees a different recordkey it reinitializes the STATIC vars
(Long var gets new recordkey and the String var gets empty). Next it adds
the Textfield to the STATIC string var seperated by comma and then returns
the STATIC string var.

Lets say you have a table like the next one :

RecID SomeTextfieldYo uWantToPopulate
1 Cat
1 Dog
2 Fish
3 Lion
3 Birth
3 Snake
4 Dog
4 Crock
4 Hyena
4 Fish

After the base query you will get:

RecID PopulatedTextfi eld
1 Cat
1 Cat, Dog
2 Fish
3 Lion
3 Lion, Birth
3 Lion, Birth, Snake
4 Dog
4 Dog, Crock
4 Dog, Crock, Hyena
4 Dog, Crock, Hyena, Fish

What the f*#%! Don't worry after the final query you will get:

1 Cat, Dog
2 Fish
3 Lion, Birth, Snake
4 Dog, Crock, Hyena, Fish

Voila!

My own code was too complex to show the basic principle, sorry!

Good luck and if you believe hard enough it will happen!

Sidney.

"Pieter Linden" <pi********@hot mail.com> schreef in bericht
news:bf******** *************** ***@posting.goo gle.com...
Don't think pure SQL will do it. You have to use code. There's code for it here:
http://www.mvps.org/access/modules/mdl0004.htm

"Return a concatenated list of sub-record values"

Nov 12 '05 #3
G'day

The word you need is "concatenat e". I hadn't had a use for that word
either until I started fiddling with this stuff.

Anyway try this for a simple concatenation of two fields that both have
values. The quotes simply put a space between the two words it is the
ampersands that do the joining.

=[Name]&" "&[Hobby]

if you have a group of possibly empty fields you might like to use a
series of immediate ifs such as

=iif(IsNull([Hobby1]),"",[Hobby1]&" ")&
iif(IsNull([Hobby2]),"",[Hobby2]).....

You will see I have also put the intermediate spaces into the iif
expression so that you do not create spaces if the fields have a null
value.

I frequently use that sort of code for concatenating (there's that word
again) town state and postcode fields so they don't look too clunky on
letters

Hope that helps

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

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

Similar topics

3
3590
by: Suzanne | last post by:
Hi, I have a form which our clients can fill in with their personal details. As part of the information we store there is a section - areas of interest - this is a number of radio buttons. I need to be able to send to a stored procedure the areas that the client has selected so these can be stored in the database.
7
4099
by: Drew | last post by:
I have a db table like the following, UID, int auto-increment RegNo Person Relation YearsKnown Now here is some sample data from this table,
6
4270
by: nboutelier | last post by:
Is it possible to apply multiple css styles to a textfield. Eg, if the value of the textfield is "foo bar" id like for 'foo' to be arial and 'bar' to be verdana. Or... id like for 'foo' to be underlined and 'bar' to be highlighted. Is this possible? -Nick
1
3188
by: John Hargrove | last post by:
I am building a database to manage test samples in an environmental laboratory. I am learning Access as I go and don't know much about the programming aspects. I hope to make the application user-friendly for the sample login people by populating form controls. Using the DLookup function, I am able to populate a form control in one record using table data. I want to be able to populate multiple records of a subform control (test...
4
2191
by: Lumpierbritches | last post by:
Thank you once again for any and all assistance. I'm building an application that's getting quite bulky due to the number of forms, macros and procedures. I was wondering if there's a way to use 1 (one) unbound form, if all the fields are the same for multiple forms populating them with Queries? I have a makeshif menu form with command buttons and I would like to eliminate all the forms and replace them with one unbound form for three...
8
1821
by: Patrick McGuire | last post by:
I have a treeview control on a windows form that I want to populate in the form's load event. The problem is that the datatable I am using to populate it contains >20,000 records, and it takes > 1 min to load the form. How can I populate it partially during load and then complete it when the user needs the complete set (i.e. when the user scrolls down)?
6
2536
by: eureka | last post by:
Hi friends, I am developing a web application using Jsp and JS. I have a main Jsp page(Jsp1).Inside it I have an iframe having an Html- table which is created dynamically and contains all records from the backend-table . For creating this dynamic table I've used another Jsp(Jsp2) and in Jsp1 I say: <iframe id = "I1" src="Jsp2.jsp" width=320 scrolling="yes">
4
2661
by: Don Do | last post by:
Help I built a form/subform/subsubform setup using the access forms wizard. I have a table1 = parent, table2 = child, table3 = (grandchild?). There will be multiple records in table2 that tie to table1, and multiple records in table 3 that tie to table2. Both on "1 to many" joins. Each of the forms are bound to the fields in the respective tables. The subform & subsubform are datasheet view. When I enter any data, I
3
3570
by: davenumber40 | last post by:
I’m creating a small database in Access 2003(XP) to track issues during software testing. As far as databases go, it’s going to be a relatively small, short term project (No more than 20,000 records in the main table over about 2 months). I have a main table (Issues) that is populated by a form (IssueAdds). On my form there is a combobox to select Opened by (who created the record). That list is populated by a table called Contacts. Here...
0
9255
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10014
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...
1
9819
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9689
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...
1
7226
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
5119
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...
1
3780
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
2
3326
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2647
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.