Error: Field is too small to accept amount of data (1 Viewer)

Ammarhm

Beginner User
Local time
Today, 08:32
Joined
Jul 3, 2008
Messages
80
Hi
I am using a VBA in access to transfer a large amount of text in a word file to access
The records in my access table are all defined as "text"
When i run the code i get this error:

Run-time error 2147217887 (80040e21)
The field is too small to accept the amount of data you attempted to add. Try inserting or pasting less data

I tried to change the record set type to memo but my db freezes then
Any suggestions??
Regards
 

MarkK

bit cruncher
Local time
Today, 08:32
Joined
Mar 17, 2004
Messages
8,186
To change the datatype of a field you need to open the table in design view.
 

Ammarhm

Beginner User
Local time
Today, 08:32
Joined
Jul 3, 2008
Messages
80
THank for the reply
I did change it in design view, i can at least that much :)
As I said, even if I change the datatype to memo it dose not solve the problem, the whole DB freezes wen i run the VBA code with the datatype set to memo
Regards
 

MarkK

bit cruncher
Local time
Today, 08:32
Joined
Mar 17, 2004
Messages
8,186
How about post the code if you think that is the problem.
Also, sometimes Access files become corrupt. If that is the case create a new empty file and import all your objects from the old file.
Cheers,
 

Ammarhm

Beginner User
Local time
Today, 08:32
Joined
Jul 3, 2008
Messages
80
Hi again
Well I am basically using the code from this site with modification as the code was originally created for use as a macro in MS Word, but I am using it in MS Access after modification

http://gregmaxey.mvps.org/Extract_Form_Data.htm

I'd really appreciate any help

Regards
 
Last edited:

GinaWhipp

AWF VIP
Local time
Today, 11:32
Joined
Jun 21, 2011
Messages
5,899
Perhaps the better question is how much TEXT? If you open Word and copy the data and then open Access and try to paste in the MEMO field do you get the same error?
 

MarkK

bit cruncher
Local time
Today, 08:32
Joined
Mar 17, 2004
Messages
8,186
If you've modified the code and there is a problem with it, how is it useful for me to look at where you got it from? What if your modifications are the problem?
Have you created a new file and imported all the objects from the old database?
 

Ammarhm

Beginner User
Local time
Today, 08:32
Joined
Jul 3, 2008
Messages
80
If you've modified the code and there is a problem with it, how is it useful for me to look at where you got it from? What if your modifications are the problem?
Have you created a new file and imported all the objects from the old database?

Thanks again for your time and effort
The only modification i did was in fact the following:

Dim myDoc As New Word.Document
Set app = New Word.Application
Set myDoc = app.Documents.Open(FileName:=oPath & FileArray(i), Visible:=False)

And changing Application.Updating to Application.Echo

Otherwise the code is exactly the same
This code is put in a module in MS Access, the database is db.accdb containing one table called "Data", in that table there is one Field named "Subject name" with data type of that field set to "Text" and I am importing data from multiple word files each containing a form field called "pid"
The error occurs when I try to import fields containing large amount of data, I tried coping the data manually to the table and I get a similar error "The text is too long to be edited", but if i change the field type to Memo and copy the same data manually it works fine, however wen running the VBA code with the field type set to Memo the whole DB freezes

Any suggestions please?


I am posting the entire code down here:

Sub ExtractInfo()

Dim oPath As String
Dim FileArray() As String
Dim oFileName As String
Dim i As Long

Dim vConnection As New ADODB.Connection
Dim vRecordSet As New ADODB.Recordset
Dim myDoc As New Word.Document
Dim FiletoKill As String
Dim Lab As String
Set app = New Word.Application
oPath = GetPathToUse
If oPath = "" Then
MsgBox "A folder was not selected"
Exit Sub
End If
'Call function to create a processed forms folder
CreateProcessedDirectory oPath
oFileName = Dir$(oPath & "*.doc")
ReDim FileArray(1 To 10) 'User a number larger the expected number of files to process
Do While oFileName <> ""
i = i + 1
FileArray(i) = oFileName
'Get the next file name
oFileName = Dir$
Loop
If i = 0 Then
MsgBox "The selected folder did not contain any forms to process."
Exit Sub
End If
'Resize and preserve the array
ReDim Preserve FileArray(1 To i)
Application.Echo False
vConnection.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;" _
& "Data Source=C:\Documents and Settings\Administrator\Desktop\My project\Test110721\db.accdb;"
vConnection.Open
vRecordSet.Open "Data", vConnection, adOpenKeyset, adLockOptimistic
vConnection.Execute "DELETE * FROM Data"
For i = 1 To UBound(FileArray)
Set myDoc = app.Documents.Open(FileName:=oPath & FileArray(i), Visible:=False)
FiletoKill = oPath & myDoc
vRecordSet.AddNew
With myDoc
If .FormFields("pid").Result <> "" Then _
vRecordSet("Subject no") = .FormFields("pid").Result

.SaveAs oPath & "Processed\" & .Name
.Close
Kill FiletoKill
End With
Next i
vRecordSet.Update
vRecordSet.Close
vConnection.Close
Set vRecordSet = Nothing
Set vConnection = Nothing
Application.Echo True
End Sub

Private Function GetPathToUse() As Variant
Dim fDialog As FileDialog
Set fDialog = Application.FileDialog(msoFileDialogFolderPicker)
With fDialog
.Title = "Select Folder containing the completed form documents to and click OK"
.AllowMultiSelect = False
.InitialView = msoFileDialogViewList
If .Show <> -1 Then
GetPathToUse = ""
Set fDialog = Nothing
Exit Function
End If
GetPathToUse = fDialog.SelectedItems.Item(1)
If Right(GetPathToUse, 1) <> "\" Then GetPathToUse = GetPathToUse + "\"
End With
End Function

Sub CreateProcessedDirectory(oPath As String)
'Requires Reference to Microsoft Scripting Runtime
Dim Path As String
Dim FSO As FileSystemObject
Path = oPath
Dim NewDir As String
Set FSO = CreateObject("Scripting.FileSystemObject")
NewDir = Path & "Processed"
If Not FSO.FolderExists(NewDir) Then
FSO.CreateFolder NewDir
End If
End Sub







Regards
Ammarhs
 

Ammarhm

Beginner User
Local time
Today, 08:32
Joined
Jul 3, 2008
Messages
80
Perhaps the better question is how much TEXT? If you open Word and copy the data and then open Access and try to paste in the MEMO field do you get the same error?

The error occurs when I try to import fields containing large amount of data, I tried coping the data manually to the table field with the field type set to Text and I get a similar error "The text is too long to be edited", but if i change the field type to Memo and copy the same data manually it works fine, however when running the VBA code with the field type set to Memo the whole DB freezes

I posted the whole code in my last post

any suggestions please?
 

MarkK

bit cruncher
Local time
Today, 08:32
Joined
Mar 17, 2004
Messages
8,186
Your database appears to lock up if you set ...
Code:
Application.Echo False
... and your code never sets it back again. Almost certainly this is what happens in your case. The screen can never refresh.
A workaround is go to the immediate window (hit <ctrl> + g) and type 'echo true' and you don't have to kill the app in task manager.
Please remove that line of code and post back about what error, if any, you receive now.
Cheers,
 

Ammarhm

Beginner User
Local time
Today, 08:32
Joined
Jul 3, 2008
Messages
80
Your database appears to lock up if you set ...
Code:
Application.Echo False
... and your code never sets it back again. Almost certainly this is what happens in your case. The screen can never refresh.
A workaround is go to the immediate window (hit <ctrl> + g) and type 'echo true' and you don't have to kill the app in task manager.
Please remove that line of code and post back about what error, if any, you receive now.
Cheers,

THank you
However, I get the same problem if i totally remove the application.echo, i.e. my DB locks up if i use the field type Memo.... don't you get the same problem if you run it without application.echo?
Regards
 

MarkK

bit cruncher
Local time
Today, 08:32
Joined
Mar 17, 2004
Messages
8,186
Setting echo to false simply stops Access from repainting the screen. That's all. It has no impact on storing or retrieving data and it only looks like your app is locked up because the screen doesn't show any changes. Can you indicate what line in your code is the last line executed before it locks up or errors out?
Do you know how to set a breakpoint and step through code?
Mark
 

Ammarhm

Beginner User
Local time
Today, 08:32
Joined
Jul 3, 2008
Messages
80
Setting echo to false simply stops Access from repainting the screen. That's all. It has no impact on storing or retrieving data and it only looks like your app is locked up because the screen doesn't show any changes. Can you indicate what line in your code is the last line executed before it locks up or errors out?
Do you know how to set a breakpoint and step through code?
Mark
HI
Thank you for the advice
I did set breakpoints, and went through the code
The last line that the compiler marks as "yellow" and after which the problem starts is the following:
Set myDoc = app.Documents.Open(FileName:=oPath & FileArray(i), Visible:=False)

Now why on earth would this line work when the field type is set to text but not when it is set to memo??

P.S this line is one of the modifications i made, by adding "app" before documents.open so that the code would work in Access in stead of Word, I already defined "app" in the line:

Set app = New Word.Application

I really appreciate your help in narrowing down the problem
 

Ammarhm

Beginner User
Local time
Today, 08:32
Joined
Jul 3, 2008
Messages
80
Solved!
Changing Set app = New Word.Application to Dim app As New Word.Application solved the whole problem, now I can import text to Memo field type
Thanks all for your help
 

Users who are viewing this thread

Top Bottom