Advertisement

10.11.2008 at 07:25PM PDT, ID: 23807255
[x]
Attachment Details

Why doesn't "DoCmd.TransferText" method on an Access object import ALL the characters in a CSV file field into an Access Database memo field?

[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

8.2
Tags:

Microsoft, Visual Basic, 6

I am writing a calendar application for my Church as follows.
     1 Outlook exports its data to a CSV file in "Windows" format.
     2. I use VB6 code to transfer the data from the CSV file into an Access database using the
         subroutine I have written named: ImportCSVFile (see below).
     3. My program then filters the Access data to process only records between
         certain dates, writing each record out to a HTML file for eventual display in a
         browser.

         (the current output from the program can be viewed on the web by going to:
          www.StThomasTheApostle.org.au/calendar.html)

My problem is that the method ".DoCmd.TransferText" within my procedure "ImportCSVFile" appears to truncate one of the fields before placing it in the Table. The table destination field is a MEMO field (since I sometimes may have more than 256 characters).

I viewed the CSV file and confirmed that the field data being imported contains  471 characters, but the method is transferring only the first 261 characters into the MEMO field.

Can anyone explain why this is happening and whether there is a way to successfully transfer all the characters - perhaps my code is faulty????

As a matter of interest the field being imported from the CSV file is NOT the last field in each of the CR/LF delimited lines of that file.

I use Access 2003 interactively on my system, but the VB Code seems to create an earlier version of the Access database when it is created (using code such as follows (the memo field in question is the last one):

                  Set CalTd = myDB.CreateTableDef("Calendar")
                  Set CalFlds(0) = CalTd.CreateField("Subject", dbText)
                  Set CalFlds(1) = CalTd.CreateField("Start Date", dbDate)
                  Set CalFlds(2) = CalTd.CreateField("Start Time", dbDate)
                  Set CalFlds(3) = CalTd.CreateField("End Date", dbDate)
                  Set CalFlds(4) = CalTd.CreateField("End Time", dbDate)
                  Set CalFlds(5) = CalTd.CreateField("All Day Event", dbBoolean)
                  Set CalFlds(6) = CalTd.CreateField("Reminder On/Off", dbBoolean)
                  Set CalFlds(7) = CalTd.CreateField("Reminder Date", dbDate)
                  Set CalFlds(8) = CalTd.CreateField("Reminder Time", dbDate)
                  Set CalFlds(9) = CalTd.CreateField("Meeting Organizer", dbText)
                  Set CalFlds(10) = CalTd.CreateField("Required Attendees", dbText)
                  Set CalFlds(11) = CalTd.CreateField("Optional Attendees", dbText)
                  Set CalFlds(12) = CalTd.CreateField("Meeting Resources", dbText)
                  Set CalFlds(13) = CalTd.CreateField("Billing Information", dbText)
                  Set CalFlds(14) = CalTd.CreateField("Categories", dbText)
                  Set CalFlds(15) = CalTd.CreateField("Description", dbMemo)
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
Option Explicit
 
Public Sub ImportCSVFile(cFileName as string, cDatabaseFileName As String,        
                                        cTableName As String)
 
'This subroutine imports data from a comma delimited file (Windows Format)
'into an Access database.
'    The three required parameters are:
'        1. the name of the CSV file to be imported (cFileName)
'                        (e.g. "C:\MyData\Calendar.CSV")
'        2. the name of the database (cDatabaseFileName)
'                        (e.g. "C:\MyDatabases\MyDataBase.mdb")
'         3. the name of the Table within that database into which the
'             delimited file is to be imported (e.g. "Calendar")
 
Dim MyWs As Workspace             'Pointer to workspace area in which Access 
                                                    'database will open
 
Dim accApp As Access.Application  'Pointer to Access database
 
Dim fs As Object                             'File pointer for Import File (cFileName)
 
'Set up a workspace in which to open the Access Database
Set MyWs = DBEngine.Workspaces(0)
 
'Set up a pointer to the Access database
Set accApp = CreateObject("Access.application")
 
'If Access 10 (97) or later then we can turn off
'the security alert that annoyingly pops up
If accApp.Version >= 10 Then
   accApp.AutomationSecurity = 1 ' msoAutomationSecurityLow
End If
 
'Open the Access database
accApp.OpenCurrentDatabase cDatabaseFileName
 
'Set up a file pointer to the text file
Set fs = CreateObject("Scripting.FileSystemObject")
'If the file exists then import the data
If fs.FileExists(cFileName) Then
  accApp.DoCmd.TransferText acImportDelim, "", cTableName, cFile, True, ""
End If
 
'Release the pointers
Set fs = Nothing
Set accApp = Nothing
Set MyWs = Nothing
 
End Sub
Answered By: boag2000
Expert Since: 02/07/2004
Accepted Solutions: 2641
Computer Expertise: Intermediate
Education: Suffolk Community College, Associate's Degree
boag2000 has been an Expert for 4 years 11 months, during which he has posted 12707 comments and answered 2641 questions. boag2000 is just one of 625 experts in the VB Database Programming Zone. 2 experts collaborated on this answer, which was graded a "B" by the asker.
 
 
20081119-EE-VQP-47 / EE_QW_2_20070628