Results 1 to 15 of 15
  1. #1
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Template (Word 2K)

    Hello all.

    I'm looking for idea's here, and am hoping for some help.

    I've been asked to create an electronic order form for our users to use.
    Word seems to be the most common platform to use, which can be E:Mailed thru a VB program I created some time ago.
    So I need Idea's on how to create the Order form with field etc for the user to fill in.

    Any Idea's would be appreciated.

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Template (Word 2K)

    Hi Dave,

    You can create a form in a Word document using the Forms toolbar. You type the fixed text, and place text boxes, dropdown lists and check boxes from the toolbar in places where the user must be able to fill in text or select something (see screenshot below). When you're done, you protect the document for forms. The user won't be able to modify the fixed text. It is possible to apply protection for forms on a section by section basis.

    A disadvantage of this approach is that the user must save the attachment, open it in Word, fill in the form, save the document, then attach it to a reply e-mail.

    An alternative would be to use a web-based form that can be filled in within the web browser. There are several applications that generate web-based forms, or you could ask in the Web Design, Coding and Scripting forum.
    Attached Images Attached Images
    • File Type: png x.PNG (4.3 KB, 0 views)

  3. #3
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Template (Word 2K)

    Thanks Hans

    Let me clarify what should happen with the document.

    Through a menu within the VB application ( Remember I showed it to you ) the user will select "E:Mail Order" .
    This will fire a new Word document using late binding and allow the user to fill in certain fields, Job No, Description etc and attach it to an E:Mail as either an attachment or embedded in the MsgNoteText section.
    Once E:mailed, the document is not saved, ie keeping the original blank source doc, possibly a .Dot template.

    What do you think ?

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Template (Word 2K)

    If you create the document using Automation, you don't need form fields, you can use a form in your VB6 application to let the user select/enter Job No etc. When the user clicks OK, you can put the values in the Word document.
    You could create all text in the document through automation, or you could have a template with either bookmarks or placeholder text where the data should go, and use code to replace these with the appropriate data.

    For example if you have placed a bookmark named JobNo in the template:
    objWordDoc.Bookmarks("JobNo").Range.Text = Me.txtJobNo
    where objWordDoc is the document object opened through Automation, and txtJobNo is a text box on your VB6 form.

    Or if you put placeholder text #JobNo# in the document:
    objWordDoc.Range.Find.Execute FindText:="#JobNo#", ReplaceWith:=Me.txtJobNo, Replace:=2
    (2 is wdReplaceAll)

  5. #5
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Template (Word 2K)

    Hans

    I think I was halfway there.
    I'm just messing with a new VB6 Form which can be loaded blank every time and insert field values direct into the message body of an E:Mail.

    I'll let you know how I get on.

  6. #6
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Template (Word 2K)

    Hans

    I never understood the word commands, it took me long enough to fumble with VB.

    Anyway, here is the form I've created, I would like to use our Header template located C:MM-DocsLongtonHeader.Dot to place the entries of these fields.
    Could you help me with this ?

    I can sort the code for attaching to an E:Mail, but haven't a clue how to place the items within the Dot.
    Attached Images Attached Images

  7. #7
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Template (Word 2K)

    As noted above, there are basically two ways you can fill the document using Automation:

    1. Insert bookmarks (Insert | Bookmark...) with meaningful names in the places where the data should go. E.g. click in the place where the Order No should be inserted, then select Insert | Bookmark..., type OrderNo (a bookmark name cannot contain spaces), then click Add. Repeat for the other data items.

    or

    2. Type unique placeholders in the places where the data should go. E.g. in the place where the Order No should be inserted, type #Order No# or something like that - it must be text that will not occur "naturally". Repeat for the other data items.

    Use Automation to create a new document based on the template, and fill in the data:

    Private Sub cmdSend_Click()
    Const strTemplate = "C:MM-DocsLongtonHeader.Dot"
    Dim objWordApp As Object ' Word.Application
    Dim objWordDoc As Object ' Word.Document

    On Error GoTo ErrHandler

    ' Start Word
    Set objWordApp = CreateObject("Word.Application")
    ' Create new document
    Set objWordDoc = objWordApp.Documents.Add(strTemplate)

    ' If you use bookmarks:
    With objWordDoc
    .Bookmarks("OrderNo").Range.Text = Me.Text1.Text
    .Bookmarks("Vehicle").Range.Text = Me.Text2.Text
    ...
    End With

    ' Or if you use placeholders:
    With objWordDoc.Find
    .Execute FindText:="#Order No#", ReplaceWith:=Me.Text1.Text, Replace:=2
    .Execute FindText:="#Vehicle#", ReplaceWith:=Me.Text2.Text, Replace:=2
    ...
    End With

    ' Send document as attachment
    objWordApp.Options.SendMailAttach = True
    objWordDoc.SendMail

    ExitHandler:
    ' Clean up
    If Not objWordApp Is Nothing Then
    objWordApp.Quit SaveChanges:=False
    Set objWordDoc = Nothing
    Set objWordApp = Nothing
    End If
    Exit Sub

    ErrHandler:
    MsgBox Err.Description, vbExclamation
    Resume ExitHandler
    End Sub

    Variations are possible, of course.

  8. #8
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Template (Word 2K)

    Do you want to have a picture in the template, later to be replaced with text from a text box on your form, or do you want to replace placeholder text in the template with a picture?

  9. #9
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Template (Word 2K)

    Hans

    How about this :
    (Might need error check adding !!)

    Can a picture be added as a place holder ?

    <pre>Private Sub cmdSend_Click()
    Dim oWord As Object
    Dim oDoc As Object
    frmWait.Show
    Set oWord = CreateObject("word.application")
    Set oDoc = oWord.Documents.Add("C:MM-UtilitiesOrder.dot")

    With oWord.selection.Find
    .Execute FindText:="#OrderNo#", ReplaceWith:=Me.Text1.Text, Replace:=2
    .Execute FindText:="#Vehicle#", ReplaceWith:=Me.Text2.Text, Replace:=2
    '...
    End With
    oDoc.saveas "C:mm-UtilitiesDW.Doc"
    oDoc.Close False
    Set oDoc = Nothing
    oWord.normaltemplate.saved = True
    oWord.quit
    Set oWord = Nothing
    Unload frmWait

    'ExitHandler:
    ' ' Clean up
    ' If Not objWordApp Is Nothing Then
    ' objWordApp.Quit SaveChanges:=False
    ' Set objWordDoc = Nothing
    ' Set objWordApp = Nothing
    ' End If
    ' Exit Sub

    'ErrHandler:
    ' MsgBox Err.Description, vbExclamation
    ' Resume ExitHandler

    End Sub</pre>


  10. #10
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Template (Word 2K)

    Hans

    On the form as earlier posted, I have an image control which will be populated as the form is loaded. (Thats the easy bit)
    It is this image I will need in the doc, so it could be any picture, perhaps I need a hidden text for the Image path on the form.

    Ideally the image will be placed after the text control data (Placeholders)

  11. #11
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Template (Word 2K)

    It would be easiest if you have the path to the image file. You can use a hidden text box for that, or a variable.

    With oWord.Selection.Find
    .Execute FindText:="#OrderNo#", ReplaceWith:=Me.Text1.Text, Replace:=2
    ...
    .Execute FindText:="#Picture#"
    oWord.Selection.InlineShapes.AddPicture FileName:=Me.txtPicturePath.Text
    End With

    where txtPicturePath is the hidden text box.

  12. #12
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Template (Word 2K)

    Hans

    How does this look:

    <pre>Private Sub cmdSend_Click()
    Dim oWord As Object
    Dim oDoc As Object
    Dim strPath As String
    strPath = "C:MM-UtilitiesOrder.doc"
    frmWait.Show
    Set oWord = CreateObject("word.application")
    Set oDoc = oWord.Documents.Add("C:MM-UtilitiesOrder.dot")

    With oWord.Selection.Find
    .Execute FindText:="#OrderNo#", ReplaceWith:=Me.Text1.Text, Replace:=2
    .Execute FindText:="#Vehicle#", ReplaceWith:=Me.Text2.Text, Replace:=2
    .Execute FindText:="#Registration#", ReplaceWith:=Me.Text3.Text, Replace:=2
    .Execute FindText:="#Customer#", ReplaceWith:=Me.Text4.Text, Replace:=2
    .Execute FindText:="#DateOnSite#", ReplaceWith:=Me.Text5.Text, Replace:=2
    .Execute FindText:="#CompletionDate#", ReplaceWith:=Me.Text6.Text, Replace:=2
    .Execute FindText:="#DescriptionOfWorkRequired#", ReplaceWith:=Me.RichTextBox1.Text, Replace:=2
    .Execute FindText:="#Picture#"
    oWord.Selection.InlineShapes.AddPicture FileName:=Me.Text7.Text

    End With
    oDoc.SaveAs "C:mm-UtilitiesOrder.Doc"
    oDoc.Close False
    Set oDoc = Nothing
    oWord.normaltemplate.saved = True
    oWord.quit
    Set oWord = Nothing
    Unload frmWait
    MAPISession1.SignOn
    With MAPIMessages1
    .SessionID = MAPISession1.SessionID
    .Compose
    .MsgSubject = "Order From " & CompName
    .MsgNoteText = strPath
    .Send True
    End With
    exitHandler:
    On Error Resume Next
    MAPISession1.SignOff
    Resume exitHandler
    End Sub</pre>


    The only problem left is .MsgNoteText = strPath this only shows the path in the message, could the doc file be inserted instead of an attachment ?

  13. #13
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Template (Word 2K)

    If you use the MAPI controls, you can only specify plain text as the body of the mail message, not a formatted document (MsgNoteText is a property of type String). So if you want a formatted document, you will have to send it as an attachment (using the AttachmentPathName property).

  14. #14
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Template (Word 2K)

    OK Hans

    Thats understood, does the rest of the code look ok?
    Thanks for the brilliant help once again.

  15. #15
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Template (Word 2K)

    The code looks fine (when you change it to attach the document), but I haven't really tested it, of course.

Posting Permissions

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