473,407 Members | 2,676 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,407 software developers and data experts.

How to take data from rows, and make new columns with it??

Hi, I have data from a form on my website in a text file, that corresponds to each visitor's input, each 13 lines in the form belongs to one visitor, as shown (twice) at the end of this message.


What I would like to do is have each visitors inputs translated to ONE row, with 13 columns/fields each. It could be appended to the same table or preferably generated in a new one. Note, there are no blank fields, some won't have data after their title, i.e. addy_line_2: is often blank, but at the very least, addy_line_2: or another field name is always there.

It would ROCK if I could also automatically take the name of each field out, i.e. each name is continuous characters up to the : (colon) ...

Thanks in advance, my Access knowledge is obviously limited, I'm sure this is fairly simple!

The fields:

Phone: 213-555-1212
Submit: Continue
addy_line_1: 1000 Melrose Place
addy_line_2:
badge:
city: Los Angeles
email:
homegroup:
name:
program:
state: CA
volunteer:
zip:
Phone:
Submit: Continue
addy_line_1:
addy_line_2:
badge:
city:
email:
homegroup:
name:
program:
state:
volunteer:
zip:

thank you thank you thank you thank you thank you !!
Mar 10 '07 #1
9 1405
ADezii
8,834 Expert 8TB
Hi, I have data from a form on my website in a text file, that corresponds to each visitor's input, each 13 lines in the form belongs to one visitor, as shown (twice) at the end of this message.


What I would like to do is have each visitors inputs translated to ONE row, with 13 columns/fields each. It could be appended to the same table or preferably generated in a new one. Note, there are no blank fields, some won't have data after their title, i.e. addy_line_2: is often blank, but at the very least, addy_line_2: or another field name is always there.

It would ROCK if I could also automatically take the name of each field out, i.e. each name is continuous characters up to the : (colon) ...

Thanks in advance, my Access knowledge is obviously limited, I'm sure this is fairly simple!

The fields:

Phone: 213-555-1212
Submit: Continue
addy_line_1: 1000 Melrose Place
addy_line_2:
badge:
city: Los Angeles
email:
homegroup:
name:
program:
state: CA
volunteer:
zip:
Phone:
Submit: Continue
addy_line_1:
addy_line_2:
badge:
city:
email:
homegroup:
name:
program:
state:
volunteer:
zip:

thank you thank you thank you thank you thank you !!
It's not as simple as you think it is but I will work on it when I get the chance.
Mar 10 '07 #2
ADezii
8,834 Expert 8TB
It's not as simple as you think it is but I will work on it when I get the chance.
The following code has been thoroughly tested and is completely functional. It does, however, rely on the exact specifications provided by you. Any deviation from these specs will cause the code to fail. All Fields in tblVisitorInput have been defined as (TEXT 50), except [ID], in order to eliminate the possibility of data mismatch errors during the Append operation. This is something that you can experiment with later.

__1. Create tblVisitorInput exactly as shown. This Table will contain exactly 14 Fields, 13 of which correspond to the 13 line segments of your Text file. Depending on the Line Numbers, data will be appended to the appropriate Fields once the Field Maximum (13) has been reached. Here are the Fields, they are all defined as (TEXT 50) except [ID] which is AutoNumber/Primary Key:
ID
Phone
Submit
addy_line_1
addy_line_2
badge
city
email
homegroup
name
program
state
volunteer
zip
__2. Here is the code that does the dirty work. Let me know if this is what you wanted and how it worked out:
Expand|Select|Wrap|Line Numbers
  1. Dim strMyLine As String, lngLineNumber As Long, strFieldValue As String
  2. Dim MyDB As Database, MyRS As Recordset
  3.  
  4. Set MyDB = CurrentDb()
  5. Set MyRS = MyDB.OpenRecordset("tblVisitorInput", dbOpenDynaset)
  6.  
  7. MyRS.AddNew
  8.  
  9. 'specify your own Path to the Text File
  10. Open "C:\Dell\Visitor Input.txt" For Input As #1
  11.  
  12. Do While Not EOF(1)
  13.   lngLineNumber = lngLineNumber + 1     'increment Line Number counter
  14.   Line Input #1, strMyLine   'Read line into variable
  15.    'Strip the Field Name, Colon, and Space from the line
  16.    strFieldValue = Right$(strMyLine, Len(strMyLine) - (InStr(strMyLine, ":") + 1))
  17.     Select Case lngLineNumber Mod 13    '13 Fields - 14th starts a New Record
  18.       Case 1    'Line 1 - Field1 in tblVisitorInput
  19.         MyRS![Phone] = strFieldValue
  20.       Case 2    'Line 2 - Field2 in tblVisitorInput
  21.         MyRS![Submit] = strFieldValue
  22.       Case 3    'Line 3 - Field3 in tblVisitorInput
  23.         MyRS![addy_line_1] = strFieldValue
  24.       Case 4    'you should get the idea by now
  25.         MyRS![addy_line_2] = strFieldValue
  26.       Case 5
  27.         MyRS![badge] = strFieldValue
  28.       Case 6
  29.         MyRS![city] = strFieldValue
  30.       Case 7
  31.         MyRS![email] = strFieldValue
  32.       Case 8
  33.         MyRS![homegroup] = strFieldValue
  34.       Case 9
  35.         MyRS![Name] = strFieldValue
  36.       Case 10
  37.         MyRS![program] = strFieldValue
  38.       Case 11
  39.         MyRS![State] = strFieldValue
  40.       Case 12
  41.         MyRS![volunteer] = strFieldValue
  42.       Case 0    'Last Field for Current Record
  43.         MyRS![zip] = strFieldValue
  44.         MyRS.Update
  45.         MyRS.AddNew
  46.       Case Else
  47.     End Select
  48. Loop
  49.  
  50. Close #1
  51. MyRS.Close
Mar 11 '07 #3
Ok, so you might get a laugh out of this one...

Thanks for the code... but where do i put it to make it work?

Is this something I can use in Access?

Thanks!!
Apr 19 '07 #4
ADezii
8,834 Expert 8TB
Ok, so you might get a laugh out of this one...

Thanks for the code... but where do i put it to make it work?

Is this something I can use in Access?

Thanks!!
Where you place the code is irrelevant, the absolut Path to Visitor Input.txt is.
Apr 19 '07 #5
Sorry to bother you again, and thanks for your help--

So do I put the code somewhere in Access? Total beginner here!
Apr 19 '07 #6
ADezii
8,834 Expert 8TB
Sorry to bother you again, and thanks for your help--

So do I put the code somewhere in Access? Total beginner here!
the easiest location would be in the Click() Event of a Command Button on an Access Form.
Apr 19 '07 #7
Thank you so much for your help!

It is coming along nicely... just one issue now:

Not all the fields are required on the form, so in the text file, some of the fields are blank.

Because of this, the output in the new tblVisitorInput has multiple records instead of only one.

When every field is filled, it works perfectly, filling each field in one record..

Any way to correct for this in the code?

Thanks!
Apr 20 '07 #8
Playing around with it more... the code doesn't like blank fields... is there an easy way to populate a blank field with an 'X', or perhaps the word "Blank"...


Thanks again!
Apr 21 '07 #9
ADezii
8,834 Expert 8TB
Playing around with it more... the code doesn't like blank fields... is there an easy way to populate a blank field with an 'X', or perhaps the word "Blank"...


Thanks again!
If a Critical Field is blank, and you do not wish to append the data into your Table, you can check for this condition in the code and not append the data. Please be more specific as to what you are looking for.
Apr 21 '07 #10

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

Similar topics

8
by: Ilan | last post by:
Hi all I need to add data from two Excel sheets (both on the same workbook) to an existing table in my SQL DB. The problem is that each sheet holds different fields for the same record, though...
6
by: DH | last post by:
I have a VERY basic question about figuring database size. I've inherited a database which is generally similar to this basic one: Item, Red, Blue, Green, Yellow (text), (int),(int),(int),(int)...
5
by: MattPF | last post by:
I have a table that is -- 30 Megabytes 90,000 rows ~65 columns My query goes SELECT city FROM table WHERE zip = 90210; It will then find about 10 matching records.
5
by: rAinDeEr | last post by:
Hi, I have a web application with a table to store terms and conditions of a Company. This may some times run into many pages and some times it may be just a few sentences. It is a character...
16
by: Ian Davies | last post by:
Hello Needing help with a suitable solution. I have extracted records into a table under three columns 'category', 'comment' and share (the category column also holds the index no of the record...
0
by: Gian Paolo | last post by:
this is something really i can't find a reason. I have a form with a tabcontrol with tree pages, in the second page there is a Data GRid View. Plus i have a class. When i open the form i...
9
by: Anil Gupte | last post by:
After reading a tutorial and fiddling, I finally got this to work. I can now put two tables created with a DataTable class into a DataRelation. Phew! And it works! Dim tblSliceInfo As New...
4
by: cuneyt.barutcu | last post by:
The following ALTER takes about 2 hours in my environment. total number of records is about 2.8 million. IS this typical? Is there a way to speed up this process. BEGIN TRANSACTION SET...
1
by: xiao | last post by:
HI~ guys , I have a program here (Sorry it is very long about 240 lines.) It can read and write the header information successfully but it cannot write the array successfully. I guess there is...
6
by: insirawali | last post by:
Hi all, I have this problem, i need to know is there a way i cn use the data adapter's update method in this scenario. i have 3 tables as below create table table1{ id1 int identity(1,1)...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...
0
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...
0
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,...
0
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...

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.