|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
|
|
#1
|
|||
|
|||
|
Saving Word Documents
Hi, am saving text box information into a word file. I have 2 problems. One is that the Word Doc ammends itself, meaning taht it continually adds the information to the Word Doc even though I am saving each file with a new name. For instance, I have Patient 1 and their data saved with the date and patient name for the Word Doc. This works fine. Then I save a second patient, and the Word Doc includes the information from the first patient and the second patient and saves it under a different file name. If I add a third patient, it will have all 3 patient records saved under a third unique filename. I need a New command or to flush the buffer. Here is my code so far:
Dim wrdApp As New Word.Application Dim wrdDoc As New Word.Document Dim dtMyDate, MyStr Dim strPatientName As String Dim strFileName As String dtMyDate = Date MyStr = Format(dtMyDate, "mmm dd, yyyy") Set wrdDoc = wrdApp.Documents.Add wrdApp.Visible = False With wrdDoc Select Case intPX Case 1 Selection.TypeText txtName.Text & Chr(13) & txtPX1.Text 'ect Case 2 Selection.TypeText txtName.Text & Chr(13) & txtPX1.Text 'ect Case 3 Selection.TypeText txtName.Text & Chr(13) & txtPX1.Text 'ect End Select ' ******* Save document under desired path & name *** strPatientName = txtName.Text strFileName = "c:\MJCC\Lab\" & strPatientName & ", " & MyStr ActiveDocument.SaveAs FileName:=strFileName, FileFormat:=wdFormatDocument End With Set wrdApp = Nothing ' Release the objects Set wrdDoc = Nothing Any idea's anyone?
__________________
Best regards, Russ Bergen Senior Software Developer and Webmaster Last edited by utmostrusselb : August 16th, 2003 at 04:16 PM. |
|
#2
|
|||
|
|||
|
Sorry, some moments are confusing:
1.What is intPX ? 2.Why do you need word documents as data storage if no data formatting is used ? But anyway, you can set Selection.ReplaceSelection = True to clear selection before you insert new patient. |
|
#3
|
|||
|
|||
|
My problem was that I did not close the active document. Regardless, I will address your quesions: 1) intPx is each lab request. It is a counter. 2) I need to save simple information to Word which does not need formatting, such as name or Doctor. I take the information from text boxes and it is fine just how it is. Thanks for your concern, but it's under control.
|
|
#4
|
||||
|
||||
|
Just a suggestion, since you aren't formatting the text but still want it in word format, it would be easy enough to just save it as a text or rtf format with a .doc extension. Word will automatically deal with the file as long as it has the right extension and it only has text in it.
|
|
#5
|
|||
|
|||
|
Quote:
You can use RichTextBox control which supports saving in text/RTF format. And it's much faster then using Word(as any OLE Automation). |
|
#6
|
|||
|
|||
|
May be this helps...
Quote:
Code:
'Should be declared as application 'The code below is an example..................... Dim wrdApp As Word.Application MyStr = Format(dtMyDate, "mmm dd, yyyy") & ".doc" Set wrdApp = New Word.Application 'released first resources With wrdApp .Documents.Add "normal.dot", , , True .... .... .... strPatientName = txtName.Text strFileName = "c:\MJCC\Lab\" & strPatientName & "_" & MyStr .ActiveDocument.SaveAs strFileName .ActiveDocument.Close .Quit End With Set wrdDoc =Nothing
__________________
I May Have Misinterpret U'r Post Correct Me If I Am Wrong......// Enjoy Coding........................../// zak2zak |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > Visual Basic Programming > Saving Word Documents |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|