Results 1 to 6 of 6
  1. #1
    pk2317 is offline Novice
    Windows XP Access 2007
    Join Date
    Oct 2010
    Posts
    9

    How do I import an RTF file into a Textbox?

    So, I think I finally found the best solution to the problem I was having earlier. What I'm going to do is, instead of trying to open the Word document in a control, I'm going to change it to an RTF (or HTML) file, and then open that in a textbox. But I can't quite figure out how to do that, and I can't quite find the right terms to Google it.



    Here's the code I'm trying to use, but all it gives me is an empty text box.

    Code:
    Private Sub cmdButton_Click()
     
        Dim dText As String
        
        Open "C:\DB\testrtf.rtf" For Binary As #1
        
        Get #1, , dText
        
        Close #1
        
        txtTest = dText
        
    End Sub
    Does anyone have any better ideas on how to do this? If I can just figure this out, I think I've found out how to change the Word file to an RTF file (Document.SaveAs FileName:= MyFile, Format:=wdFormatRTF), and I can set it up to point to the right file.

  2. #2
    weekend00 is offline I may not be right
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    1,295
    You can not simply open RFT file as input.
    following code is a simple example to save RTF to TXT file.
    Code:
    Public Sub Word2Text(wordFile As String, textFile As String)
    'wordfile is the file name with path of input RTF file
    'textFile is the file name with path for output
        Dim wordApp As Object
        Dim wordDoc As Object
        Dim p As Long
        Set wordApp = GetObject("", "word.Application")
    '    wordApp.Visible = True
        Set wordDoc = wordApp.Documents.Open(wordFile)
        Open textFile For Output As #1
        For p = 1 To wordDoc.Range.paragraphs.Count
            Print #1, CStr(wordDoc.Range.paragraphs(p))
        Next
        Close #1
        wordDoc.Close
        wordApp.Quit
        Set wordApp = Nothing
        Set wordDoc = Nothing
    End Sub

  3. #3
    pk2317 is offline Novice
    Windows XP Access 2007
    Join Date
    Oct 2010
    Posts
    9
    Correct me if I'm wrong, but in Access 2007 a TextBox has the TextFormat property, which means that the TextBox can be set to display either HTML or RichText.

    http://msdn.microsoft.com/en-us/libr...ffice.12).aspx

    So if I have a RichText-enabled TextBox, is there no way to import not only the text, but also the formatting of the source file? I feel that there has to be, but I don't know enough of the syntax to figure out how to do it.

  4. #4
    weekend00 is offline I may not be right
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    1,295
    I am not sure how to import a file to a textbox, but must not be open a file and read.

    maybe you can try to set a filename for the textbox? just like a picture?

  5. #5
    pk2317 is offline Novice
    Windows XP Access 2007
    Join Date
    Oct 2010
    Posts
    9
    Quote Originally Posted by weekend00 View Post
    I am not sure how to import a file to a textbox, but must not be open a file and read.

    maybe you can try to set a filename for the textbox? just like a picture?
    When I do this:

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

    #Name?

  6. #6
    weekend00 is offline I may not be right
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    1,295
    I don't have Access 2007, so I can not try and give more suggestion.

    Please let other people help you out.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Import XML file
    By randolphoralph in forum Programming
    Replies: 1
    Last Post: 01-22-2010, 09:12 PM
  2. Replies: 0
    Last Post: 09-23-2009, 10:52 PM
  3. Import a .sql file?
    By Alan in forum Import/Export Data
    Replies: 1
    Last Post: 06-03-2009, 07:52 PM
  4. Replies: 1
    Last Post: 03-25-2009, 02:20 PM
  5. CSV File Import
    By compasst in forum Import/Export Data
    Replies: 3
    Last Post: 03-31-2006, 09:37 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums