SunQuest
           Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
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  
Old August 16th, 2003, 04:13 PM
utmostrusselb utmostrusselb is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Location: Canada
Posts: 40 utmostrusselb User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
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.

Reply With Quote
  #2  
Old August 18th, 2003, 07:30 AM
Strannik Strannik is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 13 Strannik User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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.

Reply With Quote
  #3  
Old August 18th, 2003, 12:40 PM
utmostrusselb utmostrusselb is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Location: Canada
Posts: 40 utmostrusselb User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
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.

Reply With Quote
  #4  
Old August 18th, 2003, 01:08 PM
Onslaught's Avatar
Onslaught Onslaught is offline
/(bb|[^b]{2})/
Dev Shed Demi-God (4500 - 4999 posts)
 
Join Date: Nov 2001
Location: Somewhere in the great unknown
Posts: 4,834 Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Day 23 h 30 m 30 sec
Reputation Power: 88
Send a message via ICQ to Onslaught
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.

Reply With Quote
  #5  
Old August 18th, 2003, 02:00 PM
Strannik Strannik is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 13 Strannik User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Quote:
Originally posted by Onslaught
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.


You can use RichTextBox control which supports saving in text/RTF format. And it's much faster then using Word(as any OLE Automation).

Reply With Quote
  #6  
Old August 23rd, 2003, 05:45 AM
zak2zak zak2zak is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Location: Singapore
Posts: 34 zak2zak User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
Send a message via Yahoo to zak2zak
Lightbulb May i comment ....

May be this helps...
Quote:
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

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

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming > Saving Word Documents


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway