Results 1 to 8 of 8
  1. #1
    Join Date
    Feb 2010
    Posts
    3

    Unanswered: Import a full doc (RTF or text) into Access

    I have a set of files, that I would like to import into Access 2007.

    The table looks lile:

    ID - autonum
    title: text
    body: memo (RTF)

    For each file in a directory,

    insert into table:

    title = file name less extension (eg: 'my file name.txt' would be be 'my file name' )

    body = contents of document

  2. #2
    Join Date
    Oct 2004
    Location
    Oxfordshire, UK
    Posts
    89
    If you want to store the file in a table field, you need an OLE Object field. The memo field only stores text.

    Broadly speaking there are three ways of referencing word processing files in Access:
    1. Insert the file into an OLE field.
    2. Read the contents of the file into a memo field
    3. Record the location of the file in a memo field. The file can be opened using the default programme.

    Option 1 requires a lot of space. Access has a 2GB file limit & so big databases like SQL Server or Oracle would be better places to insert file objects. If you absolutely have to.
    Option 2 means you loose any formatting in the original document because you're only importing the text.
    Option 3 is the simplest approach.

    What do yo want to do?

  3. #3
    Join Date
    Feb 2010
    Posts
    3
    Thank you!!

    I have Access 2007, so I have set the Memo field to 'RTF' so it keeps the formatting...
    I cut-n-pasted one file and it works really well (including hyperlinks), but I have hundreds of files to import..

    The files are generally formatted as:

    Paragraph1

    paragraph2

    paragraph 'n'


    When I have tried to import a file manually, the import process created a record for each paragraph, including a row for the space between paragraphs.. what I am looking for is the entire file in one record...

    thanks!

  4. #4
    Join Date
    Dec 2004
    Location
    Madison, WI
    Posts
    3,926
    I designed this routine (http://www.dbforums.com/6433357-post94.html) to automatically import all the excel files in a folder into the mdb. I guess you could change it for word docs.

    I usually prefer to just use the shell command to open a specific word document in MSWord versus trying to import it, save it in a table, or embedd it into a form.
    Expert Database Programming
    MSAccess since 1.0, SQL Server since 6.5, Visual Basic (5.0, 6.0)

  5. #5
    Join Date
    Oct 2004
    Location
    Oxfordshire, UK
    Posts
    89
    I'm with PKStormy on using Shell to open files. I've attached an example that uses an Open File dialogue box to allow the user to select their files and record the file paths. The form displays pseudohyperlinks you can double-click on to open the files using shell. Enter a few new records and see what you think...
    Attached Files Attached Files

  6. #6
    Join Date
    Feb 2010
    Posts
    3

    Import a full doc (RTF or text) into Access

    Thanks PKStormy -
    I downloaded your DB from your earlier post...it looks quite promising..

    First let me disclose - I am not a developer
    But I am getting an error when trying to import an excel file using the DB.

    I have Access2007 on WinXP Pro SP3. The XLS files are Excel 2003 format (not .docx)
    I have attached a snapshot of the error message... have you seen this?

    Also, I am not sure what you mean by "I usually prefer to just use the shell command to open a specific word document in MSWord versus trying to import it, save it in a table, or embedd it into a form."

    Thanks in advance
    Attached Thumbnails Attached Thumbnails 2010-02-04_1300.png  

  7. #7
    Join Date
    Dec 2004
    Location
    Madison, WI
    Posts
    3,926
    It hasn't been tested on 2007. It could be that it's looking for *.xls (or different type) files but maybe 2007 doesn't use the FileSearch command like 2003 does. You may have to tweek the code for 2007 or see my last comments in this post.

    Look up help on shell.

    ex:
    Shell "WinWord.exe c:\myDocs\MyWordDoc.doc" will open your document in Word.


    As MyNewFlavor pointed out, there's ways to automate importing file names into a table (I do this also with the MainMenu example in the code bank.)

    You'll have to do some testing to see which method works best for you and 2007.

    Also check for folder names with spaces/odd characters. This often throws off ANY automated importing routine. A sub folder could also throw off the code. I'd recommend copying (only) all your excel files to a folder called something simple like: C:\MyExcelImport
    Last edited by pkstormy; 02-04-10 at 23:11.
    Expert Database Programming
    MSAccess since 1.0, SQL Server since 6.5, Visual Basic (5.0, 6.0)

  8. #8
    Join Date
    Oct 2010
    Posts
    1
    I hope thread resurrection isn't too highly frowned on here, but this seems to be the closest topic to what I'm trying to do.

    As below, I have a bunch of RTF files, and I want to display both their content (text) and formatting in a textbox on my form. I can't just cut & paste the data, because the source files may (probably will) change in the future. So what I would like to do is, during runtime, have VBA pull the contents of an RTF file into a (RichText) Memo field, so that it can be then displayed in a (RichText) textbox. What would be the correct code/syntax to accomplish this?

    When I do this:
    Code:
    txtTest.ControlSource = "C:\DB\testrtf.rtf"
    The contents of the textbox after updating are:

    #Name?



    P.S. I tried to open pkstormy's file that was linked to above, but the ZIP file gave me an error. I suspect that some of the code there may be helpful, but I can't seem to get to it.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •