locked
Forms field value to OLE object RRS feed

  • Question

  • HI,

    Friends, please help me to resolve my problem

    My data base has a form to create letter.

    Since, user of my database wants to work in MS word only. So, I made my form and Table as follows:

    1  Table (for Letter) has fields with one OLE object.

    2. When user choose a type of letter (in form), a sample data of selected letter type in OLE (in MSword format) is copied to OLE of my form from a stored table.

    3  User fills the data and modify the text in OLE as per his requirement. and complete his letter.

    4.  On save a report opens which shows fields from table and OLE.

    Now my problem :

    Some of the fields which are filled in form are required to include between the texts in the OLE object.

    For example : In form one field is << due date >>,  and in OLE text is as follows  :  

    "You need to give your confirmation within << due date >>  so that ......"

    Now user need to fill the date in form as well as in text of OLE both.

    It will be better that when user fill the due date in form same should be incorporated in text of OLE.

    Is it possible.  if any one can help me please reply

    Tuesday, January 5, 2016 5:19 AM

Answers

  • >>>These fields are required to insert at the Header of OLE (word),  Beginning of OLE(Word) and middle of OLE(word) object

    According to your description, you could refer to below code, then modify them based on your requirement:

    Dim WordObj As Object
    Me![OLEObj].Verb = -2   ' Tells Microsoft Access to open the application.
    Me![OLEObj].Action = 7  ' Activates the application.
    Set WordObj = Me![OLEObj].Object.Application.WordBasic
    
    'change field values
    WordObj.Insert "Header"
    WordObj.CharRight 2
    WordObj.Insert "Middle"
    
    WordObj.FileSave
    WordObj.FileClose (1)
    WordObj.Appclose
    Set WordObj = Nothing

    For more information, click here to refer about Visual Basic Equivalents A


    Friday, January 15, 2016 9:29 AM

All replies

  • >>>Now user need to fill the date in form as well as in text of OLE both.

    It will be better that when user fill the due date in form same should be incorporated in text of OLE.

    Is it possible.  if any one can help me please reply<<<

    According to your description, I suggest that you could open Word Documents with OLE Automation then edit, refer to below to open and close Word Documents with OLE Automation:

    Dim WordObj as Object
    Me![OLEObj].Verb = -2   ' Tells Microsoft Access to open the
                                  ' application.
    Me![OLEObj].Action = 7  ' Activates the application.
    Set WordObj = Me![OLEObj].Object.Application.WordBasic
    WordObj.EditSelectAll
    WordObj.Bold 1
    Wordobj.FileSave
    WordObj.FileClose(1)
    Wordobj.Appclose
    Set WordObj = Nothing

    For more information, click here to refer about ACC: How to Open and Close Word Documents with OLE Automation

    Wednesday, January 6, 2016 6:40 AM
  • Thank you David,

    Your post is really very helpful. 

    Now my Work became more easy not only in this form but also in other forms.

    Please help also to know

    how to insert field value in OLE (word) object opened through your above given codes.

    Thank you 

    Friday, January 8, 2016 4:20 AM
  • >>>how to insert field value in OLE (word) object opened through your above given codes.

    According to your description, you could refer to below code:

    Me.DocName = "EmailAddress.docx"
    With Me![OLEObj]
         .Enabled = True
         .Locked = False
         ' Specify what kind of object can appear in the field.
         .OLETypeAllowed = acOLEEmbedded
         ' Class statement for Word document.
         .Class = "Word.Document"
         ' Specify the file to be embedded.
         ' Type the correct path name.
         .SourceDoc = "D:\Test.docx"
         ' Create the embedded object.
         .Action = acOLECreateEmbed
         ' Optional size adjustment.
         .SizeMode = acOLESizeZoom
    End With
    DoCmd.RunCommand acCmdRecordsGoToNew

    For more information, click here to refer about ACC2000: How to Programmatically Link or Embed an Object on a Form

    Monday, January 11, 2016 7:55 AM
  • Dear David,

    Thanks for Reply,

    Sorry i was not made it clear in my previous post what actually i want.

    I want to insert data from my forms's field to OLE object (word) .  

    Form's Field contains basically text data type.  which is required to show in embeded  OLE (word).  

    and this OLE(word) object is opened through your previous post's Code :

    Dim WordObj as Object
    Me![OLEObj].Verb = -2   ' Tells Microsoft Access to open the
                                  ' application.
    Me![OLEObj].Action = 7  ' Activates the application.
    Set WordObj = Me![OLEObj].Object.Application.WordBasic
    WordObj.EditSelectAll
    WordObj.Bold 1
    Wordobj.FileSave
    WordObj.FileClose(1)
    Wordobj.Appclose
    Set WordObj = Nothing

      These fields are required to insert at the Header of OLE (word),  Beginning of OLE(Word) and middle of OLE(word) object 

    Wednesday, January 13, 2016 10:31 AM
  • >>>These fields are required to insert at the Header of OLE (word),  Beginning of OLE(Word) and middle of OLE(word) object

    According to your description, you could refer to below code, then modify them based on your requirement:

    Dim WordObj As Object
    Me![OLEObj].Verb = -2   ' Tells Microsoft Access to open the application.
    Me![OLEObj].Action = 7  ' Activates the application.
    Set WordObj = Me![OLEObj].Object.Application.WordBasic
    
    'change field values
    WordObj.Insert "Header"
    WordObj.CharRight 2
    WordObj.Insert "Middle"
    
    WordObj.FileSave
    WordObj.FileClose (1)
    WordObj.Appclose
    Set WordObj = Nothing

    For more information, click here to refer about Visual Basic Equivalents A


    Friday, January 15, 2016 9:29 AM