473,789 Members | 2,431 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Split a Text String and Append to other Table.

57 New Member
I have a table entitled Stock_Catalog. Fields include Stock_ID (random autonumber), Brand, Card_Number and Player_Name. Most of the entries have 1 name in the Player_Name field, but some show multiple players and have entry format such as Warren Spahn/Jim O'Toole/etc....

What I currently have is upon closing out the Stock_Catalog entry form, code runs to append the Player_Name to a table titled Player_Hdr where I then add details about the player.

What I want to do is figure out a manner to split that Warren Spahn/Jim O'Toole/etc.... input into multiple records in the Player_Hdr table. So the code would run and add Warren Spahn as a new record, Jim O'Toole as a new record etc etc. And I don't know how to accomplish this or even exactly where to start. I do know that the number of names in each record could be variable, mostly 1 name, but potentially up to 8 in rare cases.

Here is my existing VBA code to append Player_Name to the Player_Hdr table. Players_Hdr is set up to not allow duplicate Player_Name entries.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Close()
  2.  
  3. Dim Player_Hdr As String  
  4.  
  5. Player_Hdr = "INSERT INTO P_Hdr ( Player_Name ) SELECT Stock_Catalog.Player_Name FROM Stock_Catalog WHERE (((Stock_Catalog.Player_Name) Is Not Null))"
  6.  
  7.     DoCmd.SetWarnings False
  8.     DoCmd.RunSQL Player_Hdr
  9.     DoCmd.SetWarnings True
  10.  
  11. End Sub
I'm pretty new at VBA coding, at least seeing what does what, so I might not fully understand whatever answers come back initially so please bear with me.
Dec 23 '09 #1
5 3885
mshmyob
904 Recognized Expert Contributor
You could use the SPLIT function using the "/" character as your delimiter or better yet you could design your tables properly so you do not have this problem.

It is a sin in database design to have more than one result in a field per record. Read up on normalization and fix your table design.

cheers,
Dec 23 '09 #2
HSXWillH
57 New Member
Then if I create the player_associat ion table with the player_name and the stock_id for each player...how would I then combine all associated names into one full_descriptio n for each item?

So a id of 1234, with a brand of Topps, a card_number of 001 (text format because many cards are alpha-numeric) that has 2 players, say Ryan and Ripken. How would I then get a full_descriptio n in a query of #1234 - Topps #001 -- Ripken/Ryan?
Dec 23 '09 #3
mshmyob
904 Recognized Expert Contributor
It's called a bridge table. Figure out your business rules and design your tables based on normalization. Read here about normalization.

Give it a try and let me know your new design and I will then direct you if you are having trouble.

cheers,
Dec 23 '09 #4
NeoPa
32,579 Recognized Expert Moderator MVP
That's good advice Will.

It's much easier in a query to join things together (even in a list - see Combining Rows-Opposite of Union) than it is to have an RDBMS work on data held within a single field. Imagine particularly how unlikely it is for any optimisations to be done on data stored as sub-items within a field?

The linked article (Normalisation and Table structures from MSHMYOB's post) is actually well worth a read. It's also phrased very readably. Not too difficult for experienced and newbies alike to comprehend.
Dec 24 '09 #5
HSXWillH
57 New Member
Okay, here is what I've got after a few days of trial and error (and one persistent bug):

tblStockHeader = Stock_ID (auto# pk), Card_Year, Brand, Subset
tblStockPlayer = SPlayerID (auto# pk), Stock_ID, Player_Name
tblPlayerHeader = Player_ID (auto# pk), Player_Name, DoB
tblPlayerAttrib utes = PAttr_ID (auto# pk), Player_ID, PAttr_Desc

2 Forms are:

frmStockHeader = tblStockHeader with subform frmStockPlayer where Stock_ID carries through. Logic is a card can have multiple people on them so each is it's own record line.

frmPlayerHeader = tblPlayerHeader with subform frmPlayerAttrib utes where Player_ID carries through. Logic is Cal Ripken can have 2+ attributes such as Hall of Fame and 3000 Hits plus other.

I have set up a module using the same syntax from the link you provided about joining in a non-union format. Here is that code:

'Combination returns a list of the attributes so far found for the current ID.

Expand|Select|Wrap|Line Numbers
  1. Public Function Combination(strID As String, strAttribute As String) As String
  2.  
  3.     Static strLastID As String
  4.     Static strAttributes As String
  5.  
  6.     If strID = strLastID Then
  7.         strAttributes = strAttributes & "/" & strAttribute
  8.     Else
  9.         strLastID = strID
  10.         strAttributes = strAttribute
  11.     End If
  12.     Combination = strAttributes
  13.  
  14. End Function
When I do a query based on combining all the players associated with 1 Stock_ID, I get the information as it should be. That SQL is this:

Expand|Select|Wrap|Line Numbers
  1. SELECT tblStockPlayer.Stock_ID, Max(Combination([Stock_ID],[Player_Name])) AS Players
  2. FROM tblStockPlayer
  3. GROUP BY tblStockPlayer.Stock_ID;
This gives me Stock_ID --- Player 1/Player 2/Player 3(etc) as necessary.

However when I then alter the code for a new query to combine the attributes from players, I get an incomplete combination.

For instance, let's say my subject data is:

PAttr_ID Player_ID ....PAttr_Desc
-2030941621..... ........ 1262630099...RO Y
-474734113...... ..........12626 30099...MVP(x2)
172521253...... ...........1262 630099...400 HRs
472121878...... ...........1262 630099...HOF
543792050...... ...........1262 630099...1500 RBIs
970477108...... ...........1262 630099...3000 Hits
1262789769..... ...........1262 630099...MVP

I use code:

Expand|Select|Wrap|Line Numbers
  1. SELECT tblPlayerAttributes.Player_ID, Max(Combination([Player_ID],[PAttr_Desc])) AS Attributes
  2. FROM tblPlayerAttributes
  3. GROUP BY tblPlayerAttributes.Player_ID;
The output is
Player_ID ... Attributes
1262630099...RO Y

The same coding that works for Players doesn't work for Attributes. Is that normal? Is there something in the module I'm missing? I've even deleted the query for Players thinking something was retained in values, but nothing works.
Jan 7 '10 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

5
3272
by: oliver | last post by:
hi there i'm experimanting with imaplib and came across stringts like (\HasNoChildren) "." "INBOX.Sent Items" in which the quotes are part of the string. now i try to convert this into a list. assume the string is in the variable f, then i tried f.split() but i end up with
5
12240
by: Andy Mee | last post by:
Hello one and all, I'm developing an Asp.NET system to take a CSV file uploaded via the web, parse it, and insert the values into an SQL database. My sticking point comes when I try to split() the string returned by readline() on the file. The following code snippet works for me: tokens = "one,two,three,four".Split(",") for each token in tokens response.write("<td>"+token+"</td>")
13
11440
by: Richard Hollenbeck | last post by:
To prevent future apostrophe bugs and errors, isn't it just simpler to forbid an apostrophe from being entered into a text field? For example, couldn't "Alice's Restaurant" be changed to "Alices Restaurant" etc. automatically and programmatically during data entry? This would eliminate my concatinated strings from producing errors when I base the string on a query. Think this is an example of the "Dreaded Apostrophe Bug." If I enter a...
1
2848
by: tHeRoBeRtMiTcHeLL | last post by:
Below is an earlier post to an Excel Group.. ....but I thought that there might be a way to do this in Access by importing data and then creating append and/or update query. I would most certainly need to use the right type of table join and criteria in the query to perform the task, and don't find myself an expert or up to par as far as I'm concerned. *******************************************************************
4
3854
by: Cor | last post by:
Hi Newsgroup, I have given an answer in this newsgroup about a "Replace". There came an answer on that I did not understand, so I have done some tests. I got the idea that someone said, that the split method and the regex.replace method was better than the string.replace method and replace function. I did not believe that.
8
1655
by: Flyzone | last post by:
Hi, i have a problem with the split function and regexp. I have a file that i want to split using the date as token. Here a sample: ----- Mon Apr 9 22:30:18 2007 text text Mon Apr 9 22:31:10 2007 text
9
3015
by: =?Utf-8?B?QnJpYW4gQ29vaw==?= | last post by:
I want to open a text file and format it into a specific line and then apply color to a specific location of the text and then display it in a RichTextBox after all of this is done. I can do all of the above after the file is loaded into the RichTextBox, and I am trying to speed the process up by doing it in a temp file.
4
2558
by: Gilberto | last post by:
Hello, I have a couple of forms using the code to FIND AS YOU TYPE from Allen Browne (http://allenbrowne.com/AppFindAsUType.html). It worked PERFECTLY until yesterday when i splitted the db into FE/BE. The tables link ok and everything works ok EXCEPT this function. When i open the form it gives me a underlining line (iReturn = ctl.Parent.PageIndex IN THE PARENTNUMBER function in BOLD) and indicating that iReturn=0. I am new with access and...
7
3495
by: Johny | last post by:
I have a string of a variable length and I need to split the string in strings of 6 characters . But if the 6th character is not space then I must split the string at possition before the 6th character. For example: if the main string S is S='abcde fghc ijkl mnop'
0
9663
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
9506
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
10404
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
10193
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10136
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,...
1
7525
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
6761
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
5415
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
4089
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.