473,474 Members | 1,649 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

TransferText - Type conversion errors

204 New Member
I'm having difficulty with DoCmd.TransferText for a small comma-delimited file.
In one VBA procedure I Select a person's record from the People table, scramble the text fields for security, write it to a temporary delimited file and then email that file as an attachment to another user with their own copy of the database (same FE, different data in the BE but they need to add a copy of this particular record).

The recipient saves the file and passes it's location to a VBA procedure which executes CREATE TABLE to make an empty table with the same structure as the original, then uses TransferText to import the data to that table, unscrambles the text fields then appends it to the his People table.

At least that's the idea. In practice the import TransferText gets Error 3421, Data Type Conversion Error. Since the receiving table has the same structure as the sending table (I have checked this!) the only explanation I can think of is that the transfer file sometimes has null fields. Does anyone know if TransferText has problems handling empty fields?

The CREATE TABLE statement doesn't have any NOT NULL clauses, but it does have a lot of fields - 46 of them, including a mix of CHAR, INTEGER, BYTE, DATETIME formats, which is making it very hard for me to locate the problem. But surely TransferText should be able to import any files which it has exported?
Mar 27 '20 #1
7 1605
twinnyfo
3,653 Recognized Expert Moderator Specialist
Petrol,

During your scrambling and unscrambling of the fields, does this generate any additional commas? If so, this could be the cause.

You could change the format to Tab-delimited, which is typically not a character that would be saved in a text field.

Don't know if this will hepp....
Mar 27 '20 #2
Petrol
204 New Member
Thanks, Twinnyfo, good thought. However, no. The number of commas is just right for the 46 fields. The scrambling is very basic - it just changes alphabetic to other alphabetic, numeric digits in character fields to other numeric digits, and leaves all non-character fields untouched.

However, I could try tab-delimited - at least they might be easier for me to decode when I look at a dump of the file. But the TransferText documentation at https://docs.microsoft.com/en-us/off...d.transfertext doesn't say anything about being able to change the delimiter ... how would I do it? Or is that the same as fixed-width? My character fields vary from 1 to 200 characters in width.
Mar 27 '20 #3
twinnyfo
3,653 Recognized Expert Moderator Specialist
Would it be possible to use a Spreadsheet? You would have to scramble and unscramble each cell (and I don't know how you are doing this, but that is immaterial if you are currently doing it field by field).

Then, using TransferSpreadsheet, you could attach that file as a table and use it as a table, unscramble the data and append it directly to your permanent table without the need for creating a new, temporary table.
Mar 27 '20 #4
ADezii
8,834 Recognized Expert Expert
  1. As I see it, there should be no need to change the Delimiter.
  2. Do you have your HasFieldNames Argument set to True when it shouldn't be?
  3. In the VBA Procedure that creates the Table, set all Fields to TEXT 255 then use TransferText. If all the Fields append correctly, then it should be a simple matter to go through each Field, modify it's characteristics, and find the Offender.
  4. Should the above fail, in the VBA Procedure, after creating the Table, write VBA Code (instead of TransferText) to process the Delimited File Line-by-Line appending the Data to the appropriate Fields.
  5. Should steps 1 and 2 fail, can you Upload the VBA Procedure that creates the Import Table as well as a Sample Comma-Delimited File void of any sensitive information?
Mar 27 '20 #5
Petrol
204 New Member
Oh, how embarrassing! I had confused a few 0-origin and 1-origin variables (counter vs field number) in the unscrambling loop, so some fields were unscrambled that shouldn't have been and vice versa. :-(

I still have all the fields set to TEXT(255) as per ADezii's suggestion, and will switch them back to their proper types tomorrow and advise, but I suspect that was the problem.
Mar 28 '20 #6
Petrol
204 New Member
Sure enough, it now works with some fields defined as INTEGER, DATETIME etc.
It was ADezii's suggestion to convert the fields to TEXT on input that put me on the right track - instead of data type conversion errors I started getting Overflow errors (Error 6), and investigating that led to the discovery of the mismatched unscrambling of fields. Thank you both for your help and suggestions.

Interestingly, here's a warning for anyone else using TransferText in this way: Even though the table that was exported and the table that is imported have exactly the same specification, if the data exported has text fields that do not take the full defined width of the field it will be exported as its true length, but on import TransferText fills out the field with blanks; so the data imported does not match that exported ("This " is not the same as "This"). So you need to RTrim() the received text fields.
Mar 29 '20 #7
ADezii
8,834 Recognized Expert Expert
Glad you got it worked out, good luck with your Project.
Mar 29 '20 #8

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

Similar topics

5
by: Philip Pemberton | last post by:
Hi, I've just been trying to get some (pretty badly written) code working on a different compiler. Unfortunately, I've hit a problem. When the code below is compiled under Borland C++ it...
4
by: Master of C++ | last post by:
Hi, This is a simple question. In the following example, .. class Vector .. { .. private: .. int *Numbers; .. int vLength; ..
3
by: spamadress | last post by:
Hello I wonder why only constructors can be qualified with explicit to prevent implicit conversion, but not conversion operators. To me the following makes perfectly sense: struct A {...
4
by: Mark Oliver | last post by:
Hi, I want to put a type conversion in my class, but I don't want the conversion to be usable in a passed parameter because it makes no sense. class cData { string s; public cData(string s)...
7
by: Alphonse Giambrone | last post by:
How can I convert a string to a different type based on another string or other variable? For instance, instead of Dim i as Integer i = ctype("1000", Integer) I would like to do
5
by: Hayato Iriumi | last post by:
When converting a type to another using CType and if the type conversion fails, it throw an exception. However, in C#, there is a keyword "as" which only makes the variable Nothing (null) without...
10
by: Arno R | last post by:
Hi all, I have a database that I need to use in different versions of Access. This is A97 in most places and A2k in a few other locations. (I develop in A97 and convert the db to A2k for these...
4
by: zaeminkr | last post by:
I got a good answer here I have still confusing part. I have two very simple classes class DRect { private : double x0, y0, x1, y1; public : DRect(double a, double b, double c, double d) :...
2
by: algatt | last post by:
Hello, I am trying to compile the TPIE files but there is a file that's constantly giving errors about the templates. I am using gcc 3.4.5 on Eclipse using Windows XP. The following is the code of...
10
by: preeya | last post by:
Hi, I have written the following program: ------------------------------------------------------------------------------------------------------------- 1 #include <stdio.h> 2 #include...
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
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...
1
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
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...
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,...
1
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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...

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.