creating a document on the server (MS Word doc)

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • tamaker

    creating a document on the server (MS Word doc)

    I have a registration form where a user is able to, upon submission of
    the form, have their submission entered into a simple database... now
    Im looking to create a word document on the fly from that submission
    using this as a model to build from:


    There are no errors generated but there is NO .DOC file created at all
    either... Im not sure what Im doing wrong... any clue what I need to
    change to get this to work?


    heres the code:


    ' CREATE WORD DOCUMENT

    Set WordApp = CreateObject("w ord.application ")
    Set WordDoc = WordApp.Documen ts.Add()

    WordApp.Applica tion.Visible = False

    Set MyRange1 = WordDoc.Paragra phs.Add.Range
    MyRange1.Insert Before("Apprais al Form")
    MyRange1.Style = "Heading 1"

    Set MyRange1 = WordDoc.Paragra phs.Add.Range
    MyRange1.Insert Before("Manager : " & fname & vbcrlf & "Appraisee: "
    & lname)
    MyRange1.Font.B old = true

    Set MyRange1 = WordDoc.Paragra phs.Add.Range
    MyRange1.Insert Before(vbcrlf & "Please fill in all the required
    sections and return to HR via the internal mail system.")

    ' Set the directory location to store the generated documents
    WordDocPath = Server.MapPath( "")
    ' Use the unique session ID as the filename.
    WordDoc.SaveAs WordDocPath & "" & session.session ID & ".doc"
    WordDoc.Close
    WordApp.Quit

    Set WordDoc = Nothing
    Set WordApp = Nothing

    ' EMAIL WORD DOCUMENT

    'Set mailer = Server.CreateOb ject("ASPMAIL.A SPMailCtrl.1")
    'recipient = Email
    'sender = "vance@ukonline .co.uk"
    'subject = "Requested Form"
    'message = "Please find the requested document attached."
    'attach = WordDocPath & "\" & session.Session ID & ".doc"
    'INSERT YOUR MAIL SERVER HERE
    'mailserver = "xxx.xx.xx. xx"

    'result = mailer.SMAttach (mailserver, recipient, sender, subject,
    message, attach)



    ' DELETE WORD DOCUMENT FROM SERVER
    'Set fso = CreateObject("S cripting.FileSy stemObject")
    'fso.DeleteFile (WordDocPath & "\" & session.Session ID & ".doc")

    'Response.Write "The requested form will arrive in your inbox
    (email) within a few minutes. Please complete and return to HR
    asap."


    'Response.Write "There has been an error sending the document to
    you." & vbcrlf
    'Response.Write "Right click the following link and select ""Save
    Target As..."" to retrieve the word document." & vbcrlf & vbcrlf
    Response.Write "<A href=""" & session.Session ID & ".doc"">Generat ed
    Document</A>" & vbcrlf & vbcrlf

  • Mike Brind

    #2
    Re: creating a document on the server (MS Word doc)


    tamaker wrote:
    I have a registration form where a user is able to, upon submission of
    the form, have their submission entered into a simple database... now
    Im looking to create a word document on the fly from that submission
    using this as a model to build from:

    >
    There are no errors generated but there is NO .DOC file created at all
    either... Im not sure what Im doing wrong... any clue what I need to
    change to get this to work?
    >
    >
    heres the code:
    >
    >
    ' CREATE WORD DOCUMENT
    >
    Set WordApp = CreateObject("w ord.application ")
    Set WordDoc = WordApp.Documen ts.Add()
    >
    WordApp.Applica tion.Visible = False
    >
    Set MyRange1 = WordDoc.Paragra phs.Add.Range
    MyRange1.Insert Before("Apprais al Form")
    MyRange1.Style = "Heading 1"
    >
    Set MyRange1 = WordDoc.Paragra phs.Add.Range
    MyRange1.Insert Before("Manager : " & fname & vbcrlf & "Appraisee: "
    & lname)
    MyRange1.Font.B old = true
    >
    Set MyRange1 = WordDoc.Paragra phs.Add.Range
    MyRange1.Insert Before(vbcrlf & "Please fill in all the required
    sections and return to HR via the internal mail system.")
    >
    ' Set the directory location to store the generated documents
    WordDocPath = Server.MapPath( "")
    ' Use the unique session ID as the filename.
    WordDoc.SaveAs WordDocPath & "" & session.session ID & ".doc"
    WordDoc.Close
    WordApp.Quit
    >
    Set WordDoc = Nothing
    Set WordApp = Nothing
    >
    ' EMAIL WORD DOCUMENT
    >
    'Set mailer = Server.CreateOb ject("ASPMAIL.A SPMailCtrl.1")
    'recipient = Email
    'sender = "vance@ukonline .co.uk"
    'subject = "Requested Form"
    'message = "Please find the requested document attached."
    'attach = WordDocPath & "\" & session.Session ID & ".doc"
    'INSERT YOUR MAIL SERVER HERE
    'mailserver = "xxx.xx.xx. xx"
    >
    'result = mailer.SMAttach (mailserver, recipient, sender, subject,
    message, attach)
    >
    >
    >
    ' DELETE WORD DOCUMENT FROM SERVER
    'Set fso = CreateObject("S cripting.FileSy stemObject")
    'fso.DeleteFile (WordDocPath & "\" & session.Session ID & ".doc")
    >
    'Response.Write "The requested form will arrive in your inbox
    (email) within a few minutes. Please complete and return to HR
    asap."
    >
    >
    'Response.Write "There has been an error sending the document to
    you." & vbcrlf
    'Response.Write "Right click the following link and select ""Save
    Target As..."" to retrieve the word document." & vbcrlf & vbcrlf
    Response.Write "<A href=""" & session.Session ID & ".doc"">Generat ed
    Document</A>" & vbcrlf & vbcrlf
    I assume there is more code than this in your file - I mean you have to
    assign values to fname and lname. Have you got On error resume next
    there too? Do you have Word installed on the machine on which you are
    trying to create the document?

    --
    Mike Brind

    Comment

    • tamaker

      #3
      Re: creating a document on the server (MS Word doc)

      Yes, the other facets (definition of variables, etc,) has exsisted for
      years and works fine... I actually found out today that I was given the
      wrong info and word does NOT exist on the server... so I ditched the
      idea alltogether and am just sending out an HTML email message
      dynamically to the registrants.

      Thanks for the reply though.




      Mike Brind wrote:
      tamaker wrote:
      I have a registration form where a user is able to, upon submission of
      the form, have their submission entered into a simple database... now
      Im looking to create a word document on the fly from that submission
      using this as a model to build from:


      There are no errors generated but there is NO .DOC file created at all
      either... Im not sure what Im doing wrong... any clue what I need to
      change to get this to work?


      heres the code:


      ' CREATE WORD DOCUMENT

      Set WordApp = CreateObject("w ord.application ")
      Set WordDoc = WordApp.Documen ts.Add()

      WordApp.Applica tion.Visible = False

      Set MyRange1 = WordDoc.Paragra phs.Add.Range
      MyRange1.Insert Before("Apprais al Form")
      MyRange1.Style = "Heading 1"

      Set MyRange1 = WordDoc.Paragra phs.Add.Range
      MyRange1.Insert Before("Manager : " & fname & vbcrlf & "Appraisee: "
      & lname)
      MyRange1.Font.B old = true

      Set MyRange1 = WordDoc.Paragra phs.Add.Range
      MyRange1.Insert Before(vbcrlf & "Please fill in all the required
      sections and return to HR via the internal mail system.")

      ' Set the directory location to store the generated documents
      WordDocPath = Server.MapPath( "")
      ' Use the unique session ID as the filename.
      WordDoc.SaveAs WordDocPath & "" & session.session ID & ".doc"
      WordDoc.Close
      WordApp.Quit

      Set WordDoc = Nothing
      Set WordApp = Nothing

      ' EMAIL WORD DOCUMENT

      'Set mailer = Server.CreateOb ject("ASPMAIL.A SPMailCtrl.1")
      'recipient = Email
      'sender = "vance@ukonline .co.uk"
      'subject = "Requested Form"
      'message = "Please find the requested document attached."
      'attach = WordDocPath & "\" & session.Session ID & ".doc"
      'INSERT YOUR MAIL SERVER HERE
      'mailserver = "xxx.xx.xx. xx"

      'result = mailer.SMAttach (mailserver, recipient, sender, subject,
      message, attach)



      ' DELETE WORD DOCUMENT FROM SERVER
      'Set fso = CreateObject("S cripting.FileSy stemObject")
      'fso.DeleteFile (WordDocPath & "\" & session.Session ID & ".doc")

      'Response.Write "The requested form will arrive in your inbox
      (email) within a few minutes. Please complete and return to HR
      asap."


      'Response.Write "There has been an error sending the document to
      you." & vbcrlf
      'Response.Write "Right click the following link and select ""Save
      Target As..."" to retrieve the word document." & vbcrlf & vbcrlf
      Response.Write "<A href=""" & session.Session ID & ".doc"">Generat ed
      Document</A>" & vbcrlf & vbcrlf
      >
      I assume there is more code than this in your file - I mean you have to
      assign values to fname and lname. Have you got On error resume next
      there too? Do you have Word installed on the machine on which you are
      trying to create the document?
      >
      --
      Mike Brind

      Comment

      Working...