PDA

View Full Version : Solved: Help with word macro design...



srdennis
06-27-2005, 07:40 AM
Hello everyone,

I'm new to VBA, however I am really excited at the potentional of having a lot of cool things in the documents that I create. Right now I have two hurdles that I am trying to over come. The first is changing a birth date into an age that is representated in years and weeks. I use the following formula in excel, but would like a way to use this in a word document. The document will be printed out and become part of a patients medical record.

=ROUND(((TODAY()-A1)/365.25),0)&" years "& ROUND(((((TODAY()-A1)/365.25)-INT((TODAY()-A1)/365.25))*52),1)&" weeks "

This seems to work pretty good, but it would be cool if I could type in the birth date and have a macro covert it to an age. Any thoughts on how I can approach this from a VBA prospective?

Second, while the document has a lot of typing on it that standard, I would like to be jump between points on the document instead of moving the mouse and then clicking on where I need to add stuff. I tried creating a form which worked o.k., but the inflexibility of being able to edit stuff outside of the fields was unacceptable for a medical record. Again any thoughts on how VBA might be able to solve this would be apperciated.

Thanks

Steve Dennis

fumei
06-27-2005, 08:58 AM
1. Look up Date functions in help.

2. Could you clarify / expand your requirements for navigation? You state "jump between points". OK, but that means nothing really. WHAT points? Thnik this through. If you want to jump between points, what is the first thing you need?

Answer? Points. Which means.....you need to define, or declare, a location that IS a point. Right? What makes, say the beginning of the fourth paragraph a "point" and the beginning of the tenth paragraph NOT a point?

Defined "points" ina document are similar to a bookmark in a book. You stick a piece of paper in a book to mark a location. You stick a bunch of them in a book to mark different locations. You then can "jump" between these points easily, becasue you have "bookmarked" them.

Word has bookmarks. They can mark a single point - or they can mark chunks. Say you hace a document with 10 chapters, you can bookmark an entire chapter. You can nest bookmarks within bookmarks. You could bookmark the entire document, if you want.

Please define your requirements and we can help. There are a number of possible solutions.

RE: formfields, and the problem of not being able to edit outside the fields. The answer to this si use Continuous Section breaks. Thatway, you can exolicitly define the areas that allow edits, and those that do not.

MOS MASTER
06-27-2005, 09:03 AM
Hi and welcome to VBAX :hi:

For the first part you could use something like:
Option Explicit

Sub GiveAge()
Dim vBirth As Variant
vBirth = InputBox("Give date of birth")

If IsDate(vBirth) Then
MsgBox Age(CDate(vBirth))
End If
End Sub

Private Function Age(dtBirth As Date) As Integer
Dim dtNow As Date

If IsNull(dtBirth) Then Age = 0: Exit Function

dtNow = DateDiff("yyyy", dtBirth, Now)

If Date < DateSerial(Year(Now), _
Month(dtBirth), _
Day(dtBirth)) Then
dtNow = dtNow + 1
End If

Age = CInt(dtNow)
End Function


For the second part I go with Gerry not knowing what you want exactly...:whistle:

mdmackillop
06-27-2005, 02:50 PM
The following code attached to a form with a listbox will list all bookmarks and navigate to a selected item
Option Explicit
Private Sub UserForm_Initialize()
Dim bmk As Bookmark
For Each bmk In ActiveDocument.Range.Bookmarks
ListBox1.AddItem bmk
Next bmk
End Sub
Private Sub ListBox1_Click()
Selection.GoTo What:=wdGoToBookmark, Name:=ListBox1
End Sub

srdennis
06-27-2005, 07:56 PM
Thank you so much for those that replyed so far. I really apperciate the help. If you need help with your pets I'd be happy to give my $0.02 (I'm a veterianrian).

The document that I have is a patient examination. It looks like the document below. I would like to jump from Signalment to Reason for visit to Subjective, then to T=, P=, R=, etc. This way I can enter data that I need or leave it if there is nothing to change. At one point I created a form with fields at each of these points so that I would just tab from one field to the next, however I couldn't use the spell check and it became difficult to edit the document if I needed to take out a section or add something it that was not in a field.

I'm sorry that I don't quite know how to think about these "points", but I hope this help you enough so you can help me understand what they are.

Steve Dennis


Date Monday, June 27, 2005

Signalment: ? ?



Reason for visit:



Subjective: No medications. No V/D/C/S/PU/PD/PP/Lameness.



Objective:

General: BAR, mucus membranes pink and moist, CRT < 2 seconds, well hydrated.
T= P= R= Weight = #

EENT:

Eyes: Clear OU.

Ears: NSF.

Nose: Moist.

Throat: Tonsils in crypts.

Integument: Full, shiny coat.

Musculoskeletal: Body condition score 5/9. Symmetric. No gait abnormalities.

Cardiovascular: No murmurs auscultated. Femoral pulses moderate and synchronous.

Respiratory: All lung fields auscult clear.

Gastrointestinal: Abdomen soft, non-painful, no masses palpated, bladder small.

Urogenital: Within normal limits.

Neurologic: Within normal limits.

Lymph Nodes: Within normal limits.



Problem List:

1. .

Diagnostic Test:

1. .

Assessment:

1. .

Plan:

1. .







Steven R. Dennis, DVM

MOS MASTER
06-27-2005, 10:52 PM
Hi Steve, :yes

What you need is a UserForm that will fill in your document at the specific locations.

Just go to the VBE (ALT+F11)

Choose Insert/UserForm and use the control panel to add labels and textboxes as you like.
Arange the controls as you like.
Put the headers in the document and say something like Textbox PetName belongs here for each header.

Post the document back and we"ll code it for you so it pop's up automatically when you open a new document and help you fill it it in.

We can work from there..

Later..:whistle:

fumei
06-28-2005, 08:05 AM
Well...there are a couple of solutions. i am attaching two files (in a ZIP of course).

Vet_test1.doc - uses bookmarks to point to locations. I added a macro fire button on the main toolbar. The title is "Get Bookmarks". If you click it, a userform displays with the list of all bookmarks.

What I did was put bookmarks at the end of each of your items. However, I did not put ALL of them in. This is for demonstartion purposes.

Selecting a bookmark from the dropdown list moves the insertion point to that bookmark. Now you can jump to whereever you want to, via bookmarks. This is no different from using Insert > Bookmarks and selecting the bookmark. It just makes it a little easier with a dropdown.

Vet_Test2.doc - this file uses ActiveX controls as textboxes. You can type info into the textboxes. As most security settings when they sense ActiveX open the document in Design mode. I added code to toggle it off.

An third alternative is to use formfields.

MOS MASTER
06-28-2005, 09:07 AM
Ah..Ok..If it's only navigating your after you could add a simple sub to jump to the bookmarks. (You put arround the headers)

And create a shortcut key to fire it easily..:whistle:

fumei
06-28-2005, 09:21 AM
There are a number of solutions, or methods for navigating around a document. There are a number of solutions for gathering information. You could totally use a UserForm and then fill in the data.

A lot depends on the choices required for input. For example:

Lymph Nodes: Within normal limits.

Now, do you ever need to type text here? Could you have a set list of phrases, however many? If so, then a dropdown seems appropriate. You could use an ActiveX control, or a formfield. Selective use of Continuous Section breaks, would still allow text edit/input in determined areas of the document., For example:

******End of Protected Section ******
Gastrointestinal: Abdomen soft, non-painful, no masses palpated, bladder small.

********* Start of Protected Section *******
Urogenital: Within normal limits. ' this is a formfield
*********End of Protected Section**********

using Continuous Sections you can slice up your document into protected and unprotected sections.

MOS MASTER
06-28-2005, 09:32 AM
Yes of course Gerry..but I'm still trying to figure out what our Vet trully wants...:*)

BTW it was mentioned you could not use the spell checker within a protected document with formfields. Just for the record it is possible to do this with VBA. :whistle:

srdennis
06-29-2005, 07:51 AM
Thanks everyone for all of the help. I had no idea that I was get so many options or that you all will pitch in to help me. Since there are a couple of different ideas on how to approach this and I still need to become a little more fimillar vit VBA, I'm going to take a little time to digest all of this. Should I mark this solved?

Steve Dennis

MOS MASTER
06-29-2005, 10:18 AM
Hi Dennis, :yes

You're most welcome and do come back for aditional questions!
Yes mark the thread solved you could always add to this question or start a new one.

Later..:whistle:

srdennis
06-29-2005, 12:27 PM
Well I marked this solved, but the question that I have keep coming. I have played with the macro recorder and learned a little from the code it writes. Here is one thing that I wrote for when I spay a dog.

Sub OVHdog()
'
' OVHdog Macro
' Macro recorded 6/29/2005 by Tsunami Steve
'
Selection.Font.Name = "Arial"
Selection.Font.Size = 10
Selection.TypeText Text:="Ovariohysterectomy"
Selection.TypeParagraph

Selection.TypeText Text:="Patient was placed in anesthetized and maintained on isoflurane. Patient was placed in dorsal recumbence. The abdomen was clipped, scrubbed, and prepped for abdominal exploration. An incision was made to the linea with a #10 scaple blade. "
Selection.TypeText Text:="The subcuticular layer was released from the linea alba with metzenbaums. The linea was picked up with brown-adson tissue forceps and incised with the #10 blade. The uterus was located and followed to the left ovary. "
Selection.TypeText Text:="The proper ovarian ligament was secured with a rochester-carmalt forcep and the suspensory ovarian ligament was manually broken down. The ovarian artery and vein were isolated clamped and double ligated with _________suture. The right ovary was tied off in the same manner. "
Selection.TypeText Text:="The ovarian body was double clamped and double ligated with _______suture and removed from the abdomen. No signs of hemorrhage were noted from the ovarian or uterine pedicles. The linea alba was closed in a simple continuous pattern with __________suture."
Selection.TypeText Text:="sub-cuticular was closed in a simple continuous pattern tacking to the linea alba every third pass with__________suture. "
Selection.TypeText Text:="The skin was closed with an inter-dermal simple continuous pattern with ____________suture. The anesthetic recovery was uneventful."

'Selection.TypeText Text:="Patient was placed in anesthetized and maintained on isoflurane. Patient was placed in dorsal recumbence. The abdomen was clipped, scrubbed, and prepped for abdominal exploration. An incision was made to the linea with a #10 scaple blade. The subcuticular layer was released from the linea alba with metzenbaums. The linea was picked up with brown-adson tissue forceps and incised with the #10 blade. The uterus was located and followed to the left ovary. The proper ovarian ligament was secured with a rochester-carmalt forcep and the suspensory ovarian ligament was manually broken down. The ovarian artery and vein were isolated clamped and double ligated with _________suture. The right ovary was tied off in the same manner. The ovarian body was double clamped and double ligated with _______suture and removed from the abdomen. No signs of hemorrhage was seen from the ovarian or uterine pedicles. The linea alba was closed in a simple continuous pattern with __________suture."
'Selection.TypeText Text:="sub-cuticular was closed in a simple continuous pattern tacking to the linea alba every third pass with__________suture. The skin was closed with an inter-dermal simple continuous pattern with ____________suture. The anesthetic recovery was uneventful."

End Sub


As you can see, I have a lot of text that I want placed into the document when I run the macro. Is breaking it up into several Selection.TypeText Text:= better than a couple of really long lines? Is there a better way of doing this?

I also tried running the Sub Age() macro that Mr. Verdaasdonk wrote for me (thanks), but when I run it it from within word It says compile error. Ambigious Name detected: Age. I tried the online help, but there is a little too much specialized language at this time for me to understand it. I might be wrong, but do I need a special object library for Age? (I know that I sound like an idiot, but the terms will come with time).

Thanks again.

Steve

MOS MASTER
06-29-2005, 01:01 PM
Hi Steve, :yes
Just call me Joost.

Little time now.

Ambigious name means there is another sub somewhere in your project that's also named Age!

Normaly the VBE (Editor) will select the Ambigious name when you acknowledge the msgbox.

You can also run The menu Error (or something like that) | Compile project.
The same message will apear and the double name will be selected..

Later.:whistle:

mdmackillop
06-29-2005, 01:34 PM
Here's a possible route using autotext entries. These save a lot of typing in the code window, and are very flexible.

srdennis
06-29-2005, 02:34 PM
Hello again,
Thanks msmackillop. I like form you created. Very quick and easy to fill in. The thing that I would like to know how you did is how do you get the drop down fields into an autotext entry? Is there a limit to the number of characters in an autotext entry (255?)
I understand the first part of this I think. Isn't it just telling word to make an array of the autotext entries OV00-OV06?

Sub FillReport()
Dim MyText, MT
MyText = Array("OV00", "OV01", "OV02", "OV03", "OV04", "OV05", "OV06")

This is where I get lost. Could you tell me a little more about how this code produces the dropdown menus with in the array that allow you to pick the type of suture to use? When I look at the text in OV00-OV06 in the autotext section, I can find the where the dropdown menus will be but am not sure how to get them there.
For Each MT In MyText
ActiveDocument.AttachedTemplate.AutoTextEntries(MT).Insert_
Where:=Selection.Range, RichText:=True
Next

I think this last bit protects the document so that only the fields can be changed. Is this right

ActiveDocument.Protect Type:=wdAllowOnlyFormFields

End Sub

mdmackillop
06-29-2005, 02:49 PM
I added drop downs into your text from the Forms toolbar and inserted the optional words in its properties. I then selected the whole sentence and made it an autotext item (Insert/Autotext/New/Abbreviation), which includes the formfield.
As to size, I've just made one of 1500 words. There may be a limit, but I don't know what it is.
You're right as to the last bit. If you need to edit the main text, this would be better done before protecting the document to fill in the fields. The reason for this is that unprotecting a "completed" document can lose the field data when it is unprotected.
I did make up a utility a while ago, which stores text in a spreadsheet, that can be selected from a userform list for insertion into a document, which might be useful in conjunction with this. I'll have a look for it.

mdmackillop
06-29-2005, 03:54 PM
Here's a couple of the Excel option. Save the Excel file into C:\AAA\ or rename the path in the Userform code module (any questions, just ask!) Clicking an item on the userform will insert the text at the insertion point.

srdennis
06-30-2005, 10:48 AM
Hello everyone again. I am getting really excited about what I have created. I know that you are going to think that it is pretty basic, but the fact that I can write this and it does some of the things I need it to do is really cool. Not to mention that I am starting to understand a little VBA stuff.

Here is where I am stuck. I have writen a simple macro to enter text and format it the way I like. I have droped in 2 bookmarks. One called DOB and the other called Temperature. I have created a user form to collect several pieces of data (DOB, Temp, Pulse, Resp, Weight). I now would like to have the data go from being entered into the user form to where the book marks are within the document. If I can see how this is done I will be albe to do this for a lot of other things. I have attached my document with the macros and userform. If one of you could just take a peek at it and let me know what you think that would be great.

Steve Dennis

P.S. Thanks for the excel save option. I have not looked at this yet, but I think that I can use it to store client contact information or drop in stuff to my document that are typical treatments I do all the time.

P.S.S. I just read the last post. Maybe I can figure it out my problem from the file you created to move text from excel into word with a user form. Sorry for not reading before posting.

mdmackillop
06-30-2005, 10:53 AM
Hi Steve,
Your macros have not come with the document. They may have been saved in your Normal.dot. If you look in the VB Editor with this document open, you can drag the code modules and userform from Normal to this project (this creates a copy of them, not move them)

srdennis
06-30-2005, 10:57 AM
Thanks. It has the same name, but I copied the module and form to this document in the VB editor.

MOS MASTER
06-30-2005, 10:57 AM
Hi steve, :yes

And the attachment has no Bookmarks as well! :rofl:

MOS MASTER
06-30-2005, 11:04 AM
Ok there are no bookmarks but you could insert them in the place required.

You have a sub with the name of Bookmark that's not a good thing to have. Bookmark is a collection object in Word object library and it's not a good idea to name anything in code which sounds exactly like the thing you're using in Word

So Sub Bookmark should be named: "Sub InsertBookmark()"

Always make sure you think of such things.

You're using the change event of the textbox to fill the bookmarks. Not a good idea. It's better to fill them all at once pressing one button.

Just put another button on the Form and call it: cmdInsert.
Then use code like this to fill the bookmark:
Private Sub cmdInsert_Click()
With ActiveDocument
.Bookmarks("DOB").Range.Text = Me.tbDOB.Text
'the rest of the bookmarks
End With
End Sub


Good luck! :whistle:

mdmackillop
06-30-2005, 11:08 AM
I'll go along with Joost, but here's another way to do the same thing

Private Sub tbDOB_Change()
wb "DOB", tbDOB.Value
End Sub

'Sub to enter text in Bookmark location
Private Sub wb(ByVal BName As String, ByVal inhalt As String)
'Steiner http://www.vbaexpress.com/kb/getarticle.php?kb_id=126
If ActiveDocument.Bookmarks.Exists(BName) Then
Dim r As Range
Set r = ActiveDocument.Bookmarks(BName).Range
r.Text = inhalt
ActiveDocument.Bookmarks.Add BName, r
Else
Debug.Print "Bookmark not found: " & BName
End If
End Sub

srdennis
06-30-2005, 11:10 AM
Hello Joost!
The macro should create these two bookmarks. The DOB is on the same line as Signalment: and Temperature is right after the equals sign of T= located on the Objective line. Did the macro not do this on your computer?
I got this from using the recorder to teach me how to insert a bookmark. Does this line look right?
ActiveDocument.Bookmarks.Add Name:="DOB", Range:=Selection.Range

I understand the first part where it add a bookmark named DOB, but I don't understand how word uses the range to place the bookmark in. If I were using excel I would understand because you could just say cell A6 or something like that. Is there a better way to think about this?

Steve Dennis

P.S. Sorry I posted before I read your reply, I didn't realize you both were so fast.

mdmackillop
06-30-2005, 11:11 AM
I made up this sample userform a while ago, which demonstrates a few ways to pass data (from different sources) from a userform to a word document.
http://www.vbaexpress.com/kb/getarticle.php?kb_id=184

MOS MASTER
06-30-2005, 11:14 AM
I'll go along with Joost, but here's another way to do the same thing

Hi Malcom, :yes

My code writes to the insertion point of a bookmark or overwrites the range if it is a range bookmark.

Yours (I've one as well in my DAO example thanx to you :rofl: ) creates Ranged bookmarks that come handy if you need that value more then ones. or need to read the values back in. :whistle:

srdennis
06-30-2005, 11:17 AM
Thanks again to both of you. I really apperciate this. I have been off work for 2 days and will be heading back for the next several days, so I may not post. I'll play with what you have given me and let you know how it turns out.

Steve Dennis

mdmackillop
06-30-2005, 11:19 AM
OK Steve
I'm sure you'll come up with something useful.
Regards
MD

MOS MASTER
06-30-2005, 11:27 AM
Glad we could help Steve. :hi:

Take time to look at the examples and digest all of this. (In the little spare time a Vet has)
You're a quick learner as far as I can see so it should work out right for yah!

Now go cure some animals! :whistle:

srdennis
07-04-2005, 10:19 AM
Hello again,

So far the user form that we created is really helping me get my records writen which is great, but I am trying to make it a little more advanced. I am trying to add a combobox to allow me to pick from a few option, instead of typing a lot. The first thing that I am trying to make is a combobox that allows me to pick the species of animal that the record is for. At this time I just need to pick from a few types (dog, cat, rabbit, rat, hamster, guinne pig, bird(common), bird (exotic), snake, lizard, and other) I found this site that describes how to create an array that holds these values and then you can select from them in the drop down box, however it then inserts this value into a formfield. I would rather just stick with droping it into a bookmark thus no need to use the form and the troubles that I have with them.

The web page is http://support.microsoft.com/Default.aspx?kbid=306258

So far, if I type something into the combobox, it gets inserted into where I put a book mark, however I cannot seem to get the species to show in the dropdown box.

Could you take a look at what I have and let me know if you can see why this does not work?

Thanks again.

Steve

P.S. This is kind of a basic question about word in general, I see that I can only really store macros associated with .dot files and not .doc files. When I run this macro that I have created I create a .dot file. Since I am use to using primarly .doc files (most of my work consists of word processing) should I be saving these as .doc files? For some reason word will only save these as .dot files. Thanks as always.

mdmackillop
07-04-2005, 10:42 AM
As a starter
It is the UserForm which is initialised. You would set all initial values here.
"List" is used with 2 dimensional arrays, eg a table of two or more rows/columns. The ListIndex shows the first item in the list.

Private Sub userform_Initialize()
Dim MySpecies, MS

'Load data into ComboBox
MySpecies = Array("canine", "feline", "rat", "mouse", "guinne pig", "hamster")
For Each MS In MySpecies
cmbSpecies.AddItem MS
Next
cmbSpecies.ListIndex = 0
End Sub

mdmackillop
07-04-2005, 10:56 AM
You should put all your code, userforms and macros into a template. When you open a document based on this template (File/New/Physical Exam.dot), you should have a new document called "Documents#", which you can save with an appropriate name as a doc file. This file has access to the forms etc. in the template on which it was based.
Note that the SaveName of the file can be done using bookmarked information, but maybe save that for later!

mdmackillop
07-04-2005, 11:18 AM
Hi Steve,
I've removed the "Solved" heading as the question is ongoing.

MOS MASTER
07-05-2005, 10:54 AM
For Each MS In MySpecies
cmbSpecies.AddItem MS
Next

Hi Malcom, :yes

There is a quick method to feed the array to the combo in one line like:
cmbSpecies.List = MySpecies

Later..:whistle:

fumei
07-05-2005, 12:54 PM
I just looked at the file Physical Exam.dot.

I have a couple of questions.

Why are the bookmarks being written each time?

Why are there so many Selection.TypeText??????? First of all, if you are going to do this (and it is not a great idea) at least use With statements.

I am confused with all the hard coded text being inserted. If this is a .DOT (which it is), why is there hard coded text???

srdennis
07-05-2005, 07:22 PM
Hey there Gerry,

>Why are the bookmarks being written each time?
I'm not sure. I think that while I was getting help from everyone, I just went with something that worked for the job that I needed. Maybe you can help me write it better. Since I am very new to VBA I don't know all the ways of doing something, so once I figure out one way to do it I just repeat it. What do you mean by writing bookmarks each time?

> Why are there so many Selection.TypeText???????
Again, I am just trying to create a text document that can be edited in word easliy and that will be able to use spell check (creating a form so for has yielded simmilar results, however, it is hard edit and thus not ideal). Can you tell me how I would use With statements to make this a little better?

> I am confused with all the hard coded text being inserted. If this is a .DOT (which it is), why is there hard coded text???
Well I have to say that I really never new the difference between .DOT and .DOC files. Up until now I really have only used .DOC files and only started using .DOT because I couldn't save macros that I was creating in a .DOC file. Can you tell me the differences that you see between the file types? Is there a better filetype or way to do this?

Any help that you could provide would be great. I would love to make this as great as it can be, but only have a book, the on line help and the help that this forum provides. Please try to use simple examples as I am just learning.

Thanks in advance for you help. :-). Like I said, I'd be happy to trade any knowledge I have about animals with you.

Steve Dennis

P.S. Thank Malcom for the combo box code. It worked very well. I created 2 boxes, one to do species the other to do sex/spay or neutered.

fumei
07-06-2005, 11:50 PM
RE: using With. You can change:
Selection.Font.Name = "Arial"
Selection.Font.Size = 10
Selection.Font.Bold = wdToggle
Selection.Font.Underline = wdUnderlineSingle
Selection.TypeText Text:="Signalment:"
Selection.Font.Bold = wdToggle
Selection.Font.Underline = False
Selection.TypeText Text:=vbTab
Selection.TypeText Text:=" year old"
Selection.TypeText Text:=" "

to
With Selection
With .Font
.Name = "Arial"
.Size = 10
.Bold = wdToggle
.Underline = wdUnderlineSingle
End With
.TypeText Text:="Signalment:"
With .Font
.Bold = wdToggle
.Underline = False
End With
.TypeText Text:=vbTab
.TypeText Text:=" year old"
.TypeText Text:=" "
End With

fumei
07-07-2005, 12:41 AM
OK, next. All the hard coded text confuses me.

Are you sure you want EVERY document to have, for example,

"No Murmurs ausculted. Femoral pulses moderate and sunchronous."

This seems unusual. Does EVERY animal have "Abdomen soft, non-painful, no masses palpated"? Yet this text is hard coded. Every document will have this.

You mention spell checking. As quite a lot of the terms will bounce a spell checker, I am not sure that formfields would be a problem. Frankly, I think formfields ARE better. However, using bookmarks are good.

It seems to me this thing needs some serious design review.

Do you want to get information OUT of individual documents later?

I am posting a vesion with the items ("Subjective", Objective etc etc) already there. It is pointless to type them in every document. The bookmarks are located after. It is in a table. I put the species bookmark after SexStatus - even thoug SexStatus is not on the userform. Because it needs a space, the Species bookmark has spaces added with the value from the combobox.

Lastly, for now anyway, there is NO error trapping on the inputs. If you are going to use this to extract information out of documents later, I would put error trapping. For example, if you enter "sdkhskdhc jljle" into DOB, this will put exactly that into the bookmark.

srdennis
07-07-2005, 07:32 AM
Hey there Gerry. Thanks for the help. I really see how the with statements make the code a lot easier to read. I'll go through this and change stuff as I am working on it.

One of the things that this document serves is as a legal document. If I examine an animal and don't find anything wrong with it and 2 days later it dies, if I have just writen in the record "physical exam with in normal limits", I put myself at risk of losing my license, and the ability to practice medicine for the rest of my life. Kind of scary when you really think about it. The items that are in there are the standard things that I want as a default when I start a new record. When I create a new record, if my physical exam turns up something abnormal, then I can just either add it to the line or select the text and delete it to replace it with something else. I can see how a form would work well here, however if I needed to type in something, could I get word to spell check my entry?

There are a lot of animals that I see that have nothing wrong on physical exam, but I need to say that in a language that is acceptable to a judge, jury, and lawyer as well as my collagues who may see the animal the next time it presents for a problem. Yesterday I saw 35 animals in a 7 hour day and did 3 surgeries. I need a document that has the standard things in it so I can add the abnormal things.

The funny thing is that when something is abnormal, it usually isn't the same for every animal. If I see 6 dogs with broken legs, chances are that they will be broken in 6 different places so I need the flexibility to describe this in a record (e.g. tibial spiral fracture with comminution, epyphiseal slip of the right femoral head, slab fracture of the 3rd metarsal, etc). Would a form allow me to do this? Again would it catch the many spelling errors that I make. Since I am familliar with MS word as a word processor, I have stuck with a word type document instead of a form. I guess I could use a form, but I just don't see how it would work given what I am trying to do. What do you think?

I really like your idea of getting information out of the individual document. It would be great to be able to search these and pull up all the patients I saw for flea allergic dermatitis last year. Remember your guys are just seeing this thing from the start so it may evolve into something that could be search (which would be really cool!), but as of now is pretty simple.

I'll take a look at what you posted (the physical exam2.zip) and make those "with" changes. Since I am working most days, it may be a few before I get back with more question. If you think that creating a form that will do what I need, let me know how you envision it working and I can start to play with that as see how far it goes.

Thanks again for your help and I'll post again when I have some improvements to this project.

Steve Dennis

fumei
07-07-2005, 09:54 AM
Hi Steve.

You want to build a very sophisticated document. Fortunately for you, Word is very capable of doing this. I am finding myself quite interested in helping you get this thing properly designed and functioning. It will take some serious work.

And yes, properly designed and set up, it would be a piece of cake to have code run through a whole folder of documents, checking each one for....whatever...flea allergic dermatitis. If found, pulls info out of THAT document, dumps that into a new document (or whatever), then goes on to the next file.

You could easily construct another document that could be parts of matching information, or the whole document with matching information.

I must point out that in many ways building a database is better, or even an Excel file. However, if your needs are simple, yes, it can be done with Word. The most important point is really, really, solid design; rock hard error trapping, and fast input.

Ok, so let me get this straight. You have default text that you want to have there? So if there is abnormalities you would either ADD to the default text, or CHANGE it. Then have your default text already there. You should not be writing it. Why? If it is default, have it in already.

As i stated, I am quite interested in helping you. I would need a precise list of default text, where they apply. On your userform you could always have a Default button that could inswert the default text. Or you can have the default text already there, and have a Remove Default button. Clicking it would reveal an input textbox for putting in non-default text.

These are DESIGN issues. These are user requirements that need to be discussed and their validity determined.

There are all sorts of things you could do. You could put command buttons for each of your major items. It may in fact be better to have multiple userforms, rather than one. It depends on how many items you are going to be processing. It depends on how much you are going to be returning to adocument to update. It depends on whether when you do a second (or third, or fourth....) exam if you want to append that information onto the initial document, or make a new one. If a new one, do you want the ability to pull in information from the previous ones. If so, do you want to only get relevant items, or all items.

And on and on. Do you see what I mean? These are design issues. Frankly, while not trivial, generally speaking, the coding part of a good input document is secondary to the design. I have seen many a input document with fancy do-dah coding...but the design was so bad...who cares if it was slick coding. It did not work for the people who used it. It did not do what it was "designed" to do. Or rather it did, but the design was bad.

if you want, PM me and we can discuss off-thread.

mdmackillop
07-07-2005, 10:48 AM
Hi Gerry,
Did you see my Excel approach in Post 18 here? It needs a reference to Excel Object Library to run. Feel free to adapt it, if it's any use.

srdennis
07-10-2005, 04:54 PM
Hey there Gerry,

Thank for the offer. What does PM mean?

Steve Dennis

srdennis
07-10-2005, 07:38 PM
Another question for you guys...

I am trying to make sure that only a date can be entered into a text box. I then am trying to assign this value to a variable, but I have not done something correctly. Can you take a look at this and tell me what you think?


Sub GetDOB_change()
Dim dtmBD As Date
tbDOB=dtmBD
End Sub

Thanks

Steve Dennis

fumei
07-10-2005, 08:28 PM
Hi md, yes, and frankly, if the purpose is, in fact, to have a data system...Word is not the best..uh, doh. Excel would be an excellent route.

PM? Private Message. Click on my avatar and you can PM me.