I would like to take some data that I've cut and paste from an Excel document. the editor of the excel document has in single cells multiple "rows" of data that I would like to put on single rows of a table in Access. The affect of the multiple rows comes from a "CTRL return" I believe when creating the excel document.
When I paste the excel data into a text document, the multiple rows in the excel spreadsheet appear as a single string with a nondisplay character (representing the CRLF) delimiting them.
when I try to process this text file into a table, I wanted to use the "instr" function of VB to find the non-display character but I don't know how to represent it as the "string" to find.
I ultimately need the position of that non display character to insert the characters before it as 1 row of data and then the characters of data after it as the next row.
Any suggestions?
Thanks!
7 2585
I would like to take some data that I've cut and paste from an Excel document. the editor of the excel document has in single cells multiple "rows" of data that I would like to put on single rows of a table in Access. The affect of the multiple rows comes from a "CTRL return" I believe when creating the excel document.
When I paste the excel data into a text document, the multiple rows in the excel spreadsheet appear as a single string with a non-display character (representing the CRLF) delimiting them.
when I try to process this text file into a table, I wanted to use the "instr" function of VB to find the non-display character but I don't know how to represent it as the "string" to find.
I ultimately need the position of that non display character to insert the characters before it as 1 row of data and then the characters of data after it as the next row.
Any suggestions?
Thanks!
Here is a little code I wrote prior to going to bed which will find each occurrence of a Carriage Return (vbCr) in a String and place their positions in an Array (aCRs) for later retrieval. The only Assumption is that the String is in a Text Box named [txtTest]. The test string and code is listed below: -
'Test String in [txtTest]
-
Philadelphia
-
is
-
the
-
city
-
of
-
brotherly
-
love.
- Dim intCRPosition As Integer
-
Dim intCounter As Integer
-
Dim aCRs() As Integer 'Array to store the Positions of Carriage Returns
-
-
intCRPosition = 0 'initialize CR Position
-
-
For intCounter = 1 To Len(Me![txtTest])
-
If Mid$(Me![txtTest], intCounter, 1) = vbCr Then
-
intCRPosition = intCRPosition + 1
-
ReDim Preserve aCRs(1 To intCRPosition) 'must Redimension Array
-
aCRs(intCRPosition) = intCounter
-
End If
-
Next
-
-
For intCounter = LBound(aCRs) To UBound(aCRs)
-
Debug.Print "Carriage Return at position: " & aCRs(intCounter)
-
Next
OUTPUT: - Carriage Return at position: 13
-
Carriage Return at position: 17
-
Carriage Return at position: 22
-
Carriage Return at position: 28
-
Carriage Return at position: 32
-
Carriage Return at position: 43
NOTE: A Line Feed (vbLf) may or may not be after the Carriage Return (vbCr)
I guess that not all fields have this multiple lines problem, but some.
In a case like that I would import the textdata fields with carriage returns into a memo field and create a lookup table to hold the separate values.
After the import some code is needed to extract the multiple values from the textfield and that can be done by using the Split() function and to loop through the created array to insert a line in the lookup table for the unique key of the current record and the found array entry.
In the Split() function the vbCR or the vbCRLF can be used as indicated in the coment ofADezii.
Nic;o)
I guess that not all fields have this multiple lines problem, but some.
In a case like that I would import the textdata fields with carriage returns into a memo field and create a lookup table to hold the separate values.
After the import some code is needed to extract the multiple values from the textfield and that can be done by using the Split() function and to loop through the created array to insert a line in the lookup table for the unique key of the current record and the found array entry.
In the Split() function the vbCR or the vbCRLF can be used as indicated in the coment ofADezii.
Nic;o)
Hello Nico, good pickup on the use of the Split() Function. I was focused on the exact positions of the Carriage Returns, and did not consider its use.
Works perfectly!
The only change I had to made was due to a misunderstanding I had of the input data.
I did not realize that vbCF and vbLF could be used separately.
With the clue you gave me, I found that Excel actually creates just the 'line feed'.
When I use your code looking for vbLF in the data that I receive from Excel, it works perfectly!
This will be a very, very helpful utility for me.
Thanks!
I used the code that was created & it works great. I'm not familiar with the "Split" function. I'll read up on that approach. Thank you!
Wow... the split function is really handy.
Given that the need was identified, it was received by MSFT, they developed the function, and now it has been distributed with Visual Basic since who knows when... I guess my technical issue isn't exactly "cutting edge"!
LOL.
Thanks again. This forcum has been extremely helpful to me since discovering it. In order to resolve problems I discover, I only need to post a new question 1 in 5-10 times. Usually the problem has already been discussed.
Glad we could help.
Very good that you only needed my cryptical description to find out how the Split does work :-)
I prefer to start giving directions as I don't like to spoil the "I found it" experience :-)
Well done and success with your application !
Nic;o)
Sign in to post your reply or Sign up for a free account.
Similar topics
by: CHANGE username to westes |
last post by:
What are the most popular, and well supported, libraries of drivers for bar
code scanners that include a Visual Basic and C/C++ API? My requirements
are:
- Must allow an application to be...
|
by: Forecast |
last post by:
I run the following code in UNIX compiled by g++ 3.3.2 successfully.
: // proj2.cc: returns a dynamic vector and prints out at main~~
: //
: #include <iostream>
: #include <vector>
:
: using...
|
by: Cyde Weys |
last post by:
I'm currently working on converting a simulator program from Visual
Basic 6.0 to Visual C++ .NET. I've figured out most of the stuff, but
there's still one thing I haven't gotten to and I've never...
|
by: OG |
last post by:
I've looked on google for this but can't find an explanation.
Hopefully someone here can help.
We use DB2 Connect to link a PC application written in VB6 to OS/390
DB2 (V7) tables.
In...
|
by: Chris Lane |
last post by:
Hi,
I have been searching for a possible list that shows what methods or
properties in the System Names replace the ones in the Visual Basic Namespace
so I can stop using the Visual Basic...
|
by: boyntonboy242000 |
last post by:
Im trying to take only alphabetical characters out of what the users input to the text field (txtinput.text)..
So if i put in "The yellow man had 32 teeth!"
then im trying to get results like"...
|
by: anianu |
last post by:
i want to know how to do validation in visual basic.means how to avoid entering numbers in textbox where we need only characters and also opposite means how to avoid characters where we only need...
|
by: borophyll |
last post by:
Hi
Please let me know if I have this clear. The basic source character
set is the list of (96) characters that all implementations must have
in their vocabulary. All other characters...
|
by: Mitch |
last post by:
I'm brand new, and just started C# for Dummies.
I've also put together a list of websites with code snippets and
tutorials.
If I cut-and-paste the following line from an example into Visual...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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,...
|
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,...
|
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...
|
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...
|
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...
| |