Code to import conent of large word file

Ammarhm

Beginner User
Local time
Yesterday, 20:56
Joined
Jul 3, 2008
Messages
80
Hi all
I am writing a VBA code, this is th first step of a lrage project
WHat I am trying to do is to put all the content of a word file (.doc) into a cell in access using this code:

Private Sub Command0_Click()

Dim app As Word.Application
Dim objDoc As Word.Document
Dim sVal As String

Set app = New Word.Application
Set objDoc = app.Documents.Open("C:\Documents and Settings\Administrator\Desktop\Magic Folder\test.doc")

sVal = objDoc.Content
sqls = "INSERT INTO Table1(TextContent) VALUES ('" & sVal & "');"
DoCmd.RunSQL sqls
objDoc.Close
Set objDoc = Nothing

app.Quit
Set app = Nothing
Debug.Print sVal

End Sub

SO when I try this with a small word file it works, if the file is too large i get an error
Run time error "3075" Syntax error missing operator in query expression, after this the error message displays part of the text in my word file

2 questions:
1-Is there a better way to do what I am trying ?
2-What is wrong with my code?

Regards
 
You will get problems with text that includes any kind of quote marks. Apostrophies are the most common culprits.

They are self-escaped characters. One solution is to double them using Replace before using the variable in the code.
 

Users who are viewing this thread

Back
Top Bottom