Results 1 to 10 of 10
  1. #1
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,371

    paste to text box

    Hi Guy's, I am trying to copy an active email body to a word document and paste from word doc to a text box called txtDocMessage



    I have managed to achieve copying the email body, open word and adds the body perfect, how can I copy the word doc to text box ?

    Much appreciated as always

    Code:
    Dim WordApp As Word.Application
    Dim wdDoc As Word.Document
    Dim activeMailMessage As MailItem
    If TypeName(ActiveExplorer.Selection.Item(1)) = "MailItem" Then
        'Get a handle on the email
        Set activeMailMessage = ActiveExplorer.Selection.Item(1)
        'Ensure Word Application is open
        Set WordApp = CreateObject("Word.Application")
        'Make Word Application visible
        WordApp.Visible = True
        'Create a new Document and get a handle on it
        Set wdDoc = WordApp.Documents.Add
        'Copy the formatted text:
        activeMailMessage.GetInspector().WordEditor.Range.FormattedText.Copy
        'Paste to the word document
        wdDoc.Range.Paste
        'Clear the clipboard entirely:
        ' Call ClearClipBoard
    End If

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,772
    What do you mean by 'paste the word doc'? You want all text in Word document selected and copy/paste to a textbox in Access?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,371
    Hi June7 is exactly what i am looking for, i will probably add new record to save the contents additional to question but if it is pasted to a text box, i can save for that, in fact better i do it that way as i can check contents before saving

  4. #4
    Minty is offline VIP
    Windows 10 Access 2016
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,158
    Am I missing something, why not simply copy the email directly to the text box ?
    Is it available in a local outlook session?
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  5. #5
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,371
    Hi minty, yes that would be great, would you be able to send an example in vba ?

    Much appreciated

  6. #6
    Minty is offline VIP
    Windows 10 Access 2016
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,158
    It's not something I have done personally, however a quick google brought this up;
    https://stackoverflow.com/questions/...46315#12146315 for excel, but should give you some ideas.

    And I'm sure I've seen other examples, both here and on some other forums.
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  7. #7
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,371
    Hi minty, all you guy's out there are fab

    I have played and this very simple code does the trick

    Code:
    Dim activeMailMessage As MailItem
    
    If TypeName(ActiveExplorer.Selection.Item(1)) = "MailItem" Then
    
    
        Set activeMailMessage = ActiveExplorer.Selection.Item(1)
        
        Me.txtMailBody = activeMailMessage
    
    
    End If

  8. #8
    Minty is offline VIP
    Windows 10 Access 2016
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,158
    Excellent - much simpler solution.
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  9. #9
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,371
    Ahh just copies the subject and not the mail body, yet when added to a word doc, it copies and pastes the body ??

    Any ideas ?

  10. #10
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,772
    This works for me.
    Code:
    Public Sub ImportEmails()
    ' Set up Outlook objects.
    Dim ol As New Outlook.Application
    Dim of As Outlook.MAPIFolder
    Dim objItems As Outlook.Items
    Dim mo As Outlook.MailItem, Atmt As Outlook.Attachment
    'Set of = ol.GetNamespace("Mapi").GetDefaultFolder(olFolderInbox).Folders("Repairs")
    Set of = ol.GetNamespace("Mapi").GetDefaultFolder(olFolderInbox)
    Set objItems = of.Items
    Dim rst As DAO.Recordset
    Set rst = CurrentDb.OpenRecordset("tblEmails")
    For Each mo In objItems
        rst.AddNew
        rst!Sender = mo.SenderEmailAddress
        rst!SenderName = mo.Sender
        rst!Subject = mo.Subject
        rst!body = mo.body
        rst!Received = mo.ReceivedTime
        rst.Update
        'For Each Atmt In mo.Attachments
        '    Atmt.SaveAsFile "C:\Users\June\Forums\" & Atmt.FileName
        'Next
    Next
    End Sub
    Or for only selected emails in Outlook.
    Code:
    Sub GetEmailBody()
    Dim objOL As Outlook.Application
    Dim objMsg As Outlook.MailItem 'Object
    Dim objSelection As Outlook.Selection
    Dim strFolderPath As String
    ' Get the path to your My Documents folder
    strFolderPath = CreateObject("WScript.Shell").SpecialFolders(16)
    On Error Resume Next
    ' Instantiate an Outlook Application object.
    Set objOL = CreateObject("Outlook.Application")
    ' Get the collection of selected objects.
    Set objSelection = objOL.ActiveExplorer.Selection
    For Each objMsg In objSelection
        Debug.Print objMsg.body
    Next
    End Sub
    And look at this one. Should be able to include WHERE clause in the SQL.
    Code:
    Sub InboxImport()
        Dim SqlString As String
        Dim ConnectionString As String
        Dim EmailTableName As String
        Dim UserIdNum As String
        Dim EmailAddr As String
        Dim ol As Outlook.Application
        Dim olNS As Outlook.NameSpace
        Dim olFol As Outlook.folder
        'Dim rs As DAO.Recordset    Set ol = CreateObject("Outlook.Application")
        Set olNS = ol.GetNamespace("MAPI")
        Set olFol = olNS.GetDefaultFolder(olFolderInbox)
        EmailTableName = "MyInbox"
        UserIdNum = Environ("USERNAME")  '1277523A...
        EmailAddr = olFol.Parent.Name 'Gives your user email address
        ConnectionString = "Outlook 9.0;MAPILEVEL=" & EmailAddr & "|;PROFILE=Default Outlook Profile;TABLETYPE=0;TABLENAME=MyInbox;COLSETVERSION=12.0;DATABASE=C:\Users\" & UserIdNum & "\AppData\Local\Temp\"
        'SqlString = "SELECT [From] As [Sender], [Sender Name] As [SenderName], [Subject Prefix] & [Normalized Subject] As Subject, [Contents] As [Body], [Received] As [ReceivedTime]" & _
                " INTO [MyInbox]" & _
                 " From [" & ConnectionString & "].[Inbox]"
        SqlString = "INSERT INTO MyInbox SELECT [From] As [Sender], [Sender Name] As [SenderName], [Subject Prefix] & [Normalized Subject] As Subject, [Contents] As [Body], [Received] As [ReceivedTime]" & _
                 " FROM [" & ConnectionString & "].[Inbox]"
        'CurrentDb.Execute SqlString
        Debug.Print SqlString
    End Sub
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. Paste as plain text in richtext text box
    By veejay in forum Forms
    Replies: 8
    Last Post: 01-09-2019, 09:06 AM
  2. Copy and paste plain text.
    By 316854 in forum Access
    Replies: 9
    Last Post: 12-14-2015, 09:16 PM
  3. Won't paste text if first 5 records are numbers
    By nigelbloomy in forum Access
    Replies: 2
    Last Post: 10-13-2014, 03:08 PM
  4. VBA - copy memo, paste as text in email app
    By Goodge12 in forum Programming
    Replies: 5
    Last Post: 09-10-2014, 12:12 PM
  5. Replies: 1
    Last Post: 05-01-2014, 11:33 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