| Chat with a LIVE Microsoft
Access Expert! |
||||
|
||||
|
|||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
I have 2 columns of data, perfectly consistent... The 1st column is like a tag that states this is field 01 = Name , field 02 = Address , field 03 = City , field 04 = ZIP the 2nd column is the data that belongs in that field. Current Data: 01 Patrick 02 Main St 03 Springfield 04 12345 01 Roger 02 Elm St 03 Boston 04 02241 01 Mary 02 Canal St 03 Waco 04 87645 Desired Excel Spreadsheet 5 Columns : Record1Patrick Main St Springfield 12345 Record2 Roger Elm St Boston 02241 Record3 Mary Canal St Waco 87645 In this example this should be just 3 Rows with the 4 fields filled in (5 if a record counter is created). Current Data: My 2 Columns of data in an Access Table are really 53 rows of data each for (50,000 sets of data) - that makes 2,650,000 records in the DB. Note: It was imported from a Fixed Width TXT File (columns 1 - 2 are the filed, 3 - 50 is the data) so if something can be done for importing into Access into 53 columns - that would work too! Goal: I need to create a single EXCEL spreadsheet that is 53 Columns Wide and 50,000 rows. If I parsed it straight into Excel would equate to 41 TABS and then I'd need to convert them with Vlookup or Pivot Tables which will not work... I'm hoping there is a 'script' that I can run to populate the data into Excel as a Matrix / Array??? or that on import into Access it can use the 1st column to place the data in the appropriate column... Does anyone know a method to do this using Access / Excel tools ? |
| Sponsored Links |
|
#2
|
||||
|
||||
|
Re: Converting 2 Field Data set (column 1 tag) into a 53 Column database
You need to go back to the start and import the file as fixed width delimited file and define your spec accordingly. This will them import all the fields into seperate ones. Have you got a sample of the incoming delimited file to look at?
__________________
David Crake www.xcraftlimited.co.uk The Home of Simple Software Solutions. O/S Windows XP (SP3) & Windows 7 64bit Access 2003 (version 11.0) Access 2007 (version 12.0) Remember when posting sample databases you will get a better response if it is pre Access 2007 - not all people have it installed. |
|
#3
|
|||
|
|||
|
Re: Converting 2 Field Data set (column 1 tag) into a 53 Column database
It looks exactly similar to the sample with the first 2 charachters identifying the field. Then colms 3 through 50 are the actual pieces of data. The sets are 53 line each.
I'd like to be able to import and convert, the first instance of 01 indicating record 1, then put that data begenning with 01 into Name, then place next row (starts with 02) into Address, then the next row (starts with 03) into the City field etc... The data raw looks like (no spaces): 01Patrick 02Main St 03Springfield 0412345 01Roger 02Elm St 03Boston 0402241 01Mary 02Canal St 03Waco 0487645 |
|
#4
|
||||
|
||||
|
Re: Converting 2 Field Data set (column 1 tag) into a 53 Column database
To do this you will need to use VBA my only concern is the size of the incoming file. What is the ballpark size of the file you are wanting to import? Also what are your vba skills like?
__________________
David Crake www.xcraftlimited.co.uk The Home of Simple Software Solutions. O/S Windows XP (SP3) & Windows 7 64bit Access 2003 (version 11.0) Access 2007 (version 12.0) Remember when posting sample databases you will get a better response if it is pre Access 2007 - not all people have it installed. |
|
#5
|
|||
|
|||
|
Re: Converting 2 Field Data set (column 1 tag) into a 53 Column database
There are 15 files a day, most of the files are about 530,000 lines (10,000 real records) but there is usually at least 1 file a day that is > 50,000 records which is produced in a file that that is 2.8 million records...
My skills are VBA skills are not strong. I am an expert in Excel, I've created many advanced Macros in Excel but created them mostly through "record macro" and then combined / edited them based what I really needed the Macros to do. Years ago I programmed in DBASE 3+ so I very strong logic skills just not with VBA. |
|
#6
|
||||
|
||||
|
Re: Converting 2 Field Data set (column 1 tag) into a 53 Column database
Here is the concept of how I would do it.
Get the name of the file to import Create recordset base on the table that the data is going into Open the file using Open File For Input As #1 Loop this file until eof As we know there are 53 fields per record I would set up a loop from 1 to 53 I would then use the loop number to add the data to the corresponding ordinal number field in the table ussing .AddNew and .Update Close the txt file For example Rs.AddNew input line "01 Fred" Rs(1) = Mid(Text,3) Would be appended to field 1 in the table input line "02 Jones" Rs(2) = Mid(Text,3) Would be appended to field 2 in the table input line "53 True" Rs(53) = Mid(Text,3) Would be appended to field 53 in the table Rs.Update Remembering that field 0 is the autonumber field that is self populating also if certain fields are numeric or dates etc you need to ensure that Access adds them as the right data type.
__________________
David Crake www.xcraftlimited.co.uk The Home of Simple Software Solutions. O/S Windows XP (SP3) & Windows 7 64bit Access 2003 (version 11.0) Access 2007 (version 12.0) Remember when posting sample databases you will get a better response if it is pre Access 2007 - not all people have it installed. |
|
#7
|
|||
|
|||
|
Re: Converting 2 Field Data set (column 1 tag) into a 53 Column database
Thank you. I will give that a whirl.
|
|
#8
|
|||
|
|||
|
Re: Converting 2 Field Data set (column 1 tag) into a 53 Column database
Solved:
Step 1: Setup Table Structures TABLE STRUCTURES Table Name 1: Data_in_2_Columns Fiels Numbers Fields Names Data Type Field 1 Tag Text Field 2 Data Text Field 3 ID AutoNumber Table Name 2 Data_in_Database_Columns Fiels Numbers Fields Names Data Type Field 1 ID AutoNumber Field 2 fld1 text Field 3 fld2 text Field 4 fld3 text Field 5 fld4 text Field 6 fld5 text Note: Create Columns based on number of columns in the data Step 2: Import Data into Table 1 (Data_in_2_Columns)
Dim rs1 As ADODB.Recordset Dim rs2 As ADODB.Recordset Dim cn As Connection Dim strsql As String Dim blnNew As Boolean Set cn = CurrentProject.Connection strsql = "SELECT * FROM Data_in_2_Columns order by ID;" Set rs1 = New ADODB.Recordset rs1.Open strsql, CurrentProject.Connection Set rs2 = New ADODB.Recordset With rs2 .ActiveConnection = CurrentProject.Connection .Source = "Data_in_Database_Columns" .LockType = adLockOptimistic .CursorType = adOpenDynamic .Open End With blnNew = False Do While Not rs1.EOF Debug.Print rs1(0) Select Case Trim(rs1("tag")) 'trim is incase of unintentional leading spaces - if there should be remove the Trim Case "00" 'Tag Name (in example tags are 00, 01, 02, 03, 04) 'start new record If blnNew = True Then rs2.Update End If rs2.AddNew blnNew = True rs2("fld1") = rs1("data") Case "01" rs2("fld2") = rs1("data") Case "02" rs2("fld3") = rs1("data") Case "03" rs2("fld4") = rs1("data") Case "04" rs2("fld5") = rs1("data") End Select rs1.MoveNext Loop rs1.Close rs2.Update rs2.Close Set rs1 = Nothing Set rs2 = Nothing End Sub |
| Sponsored Links |
![]() |
| Tags |
| access 2003, convert, excel, txt |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| need help in automatic updating database from xml | pushkar1986 | Modules & VBA | 5 | 08-31-2009 07:40 PM |
| Beginner's Guide to ODBC | Banana | Access FAQs | 4 | 06-18-2009 08:10 PM |
| Removing Security | sanmisds | General | 3 | 05-21-2009 01:38 AM |
| Splitted MDB created problem with FindAsYouType | Gilfdz | Modules & VBA | 1 | 11-13-2007 02:14 AM |
| Import multiple text files using DTS package | COLB333 | Modules & VBA | 4 | 11-01-2007 08:36 AM |