recalling a userform and resetting document 
Author Message
 recalling a userform and resetting document

Thank you again Doug for your help.

Just one more question, once I check the boxes to select the sentences I
want into my report and activate the command button, the report is created,
exactly as I wanted it, and the form disappears (UserForm1.Hide). But if for
some reason I notice an error, I recall the autonew macro, the same items
are placed again in the document. I would like the document to be recreated
each time I launch the macro. or better, I would like the paragraph in which
I insert the sentences to be recreated, with the rest of my document being
untouched...

Is there a way to empty all places by default ? I mean all checkboxes would
be empty by default when autonew is launched, but also  the document would
be cleared from the possibly wrongly inserted sentence ? (except creating a
new document of course...)

TIA
--
-------------------------------
Lorenzo Sandini
Kirurgian Klinikka
Kansanterveyden Tutkimuslaitos
Kuopion Yliopisto
Tieoteknia - OSTPRE
70200 Kuopio
FINLAND
--------------------------

Hi Lorenzo,

Time to jump in to the deep end.

I would suggest using a UserForm for this purpose.

First take a look at "How to create a UserForm" at

http://www.*-*-*.com/

Then, instead of putting textboxes on the userform, use a checkbox for each
sentence, and put the sentence as the caption in an adjacent label.

Then in the CommandButton Click event code, use the following

If CheckBox1.Value = True Then
    ActiveDocument.Bookmarks("Sentence1").Range.InsertBefore Label1.Caption
End If

etc for each CheckBox

This is assuming that you place Bookmarks in the template named Sentence1,
... Sentencen  for each possible sentence and that caption of label1,
coincides with what you want for Sentence1.

Please post any follow-up or new questions to the Newsgroups so that others
may benefit therefrom or contribute thereto.

Hope this helps,
Doug Robbins - Word MVP

Quote:
> Hi,

> I am a complete newbie in the world of macros so please don't laugh  :o)

> What I am trying to do is to write some standard report for each patient
who
> comes for a medical visit (a specialized bone ultrasound measuring
method).
> In this report, I would like to insert a few comments about the medical
> history of my patients, and these comments are the answers to some very
> basic questions.

> I already did 10 short macros who insert a string of text, and then I made
a
> new toolbar with a button for each of them, so by clickng on them one by
> one, I build my report. The various sentences that are inserted with each
> macro are simple so they can be put one after another and the resulting
text
> is quite acceptable, no matter in what order I put them.

> I was hoping to find a way of doing it like this : I would have some place
> in the page where I would just put a cross in checkboxes for the sentences
I
> want in my report, then I would use one macro to build all the text from
the
> selected checkboxes. The checkboxes would be hidden (not printed), only
used
> by the physician or technician who writes the report.

> Any idea about how to do this ?

> TIA
> --
> -------------------------------
> Lorenzo Sandini
> Kirurgian Klinikka
> Kansanterveyden Tutkimuslaitos
> Kuopion Yliopisto
> Tieoteknia - OSTPRE
> 70200 Kuopio
> FINLAND
> --------------------------



Tue, 16 Sep 2003 05:15:53 GMT  
 recalling a userform and resetting document
Hi Lorenzo,

In this case it might be better to take a slightly different approach using
document variables instead of bookmarks to hold the information

The following is the code that you would use in the userform

Private Sub CommandButton1_Click()
'    Delete any existing variables from the document
Dim avariable As Variable
For Each avariable In ActiveDocument.Variables
    avariable.Delete
Next avariable
'    Create a variable for each check box.  If the check box is checked,
'    the variable is loaded with the sentence contained in the caption of
'    the check box.  If it is not checked, the variable is left empty.
If CheckBox1.Value = True Then
    ActiveDocument.Variables.Add Name:="Test1", Value:=CheckBox1.Caption
Else
    ActiveDocument.Variables.Add Name:="Test1", Value:=" "
End If
If CheckBox2.Value = True Then
    ActiveDocument.Variables.Add Name:="Test2", Value:=CheckBox2.Caption
Else
    ActiveDocument.Variables.Add Name:="Test2", Value:=" "
End If
UserForm1.hide
ActiveDocument.Fields.Update
End Sub

Private Sub UserForm_Activate()
'    Clear the check boxes on loading the form
CheckBox1.Value = False
CheckBox2.Value = False
End Sub

In place of bookmarks, insert  Docvariable fields in your document (select
Fields from the Insert menu, then select the Document Automation category
and select DocVariable and then enter the name of the variable inside quote
marks, such as DOCVARIABLE "Test1"

Please post any follow-up or new questions to the Newsgroups so that others
may benefit therefrom or contribute thereto.

Hope this helps,
Doug Robbins - Word MVP

Quote:
> Thank you again Doug for your help.

> Just one more question, once I check the boxes to select the sentences I
> want into my report and activate the command button, the report is
created,
> exactly as I wanted it, and the form disappears (UserForm1.Hide). But if
for
> some reason I notice an error, I recall the autonew macro, the same items
> are placed again in the document. I would like the document to be
recreated
> each time I launch the macro. or better, I would like the paragraph in
which
> I insert the sentences to be recreated, with the rest of my document being
> untouched...

> Is there a way to empty all places by default ? I mean all checkboxes
would
> be empty by default when autonew is launched, but also  the document would
> be cleared from the possibly wrongly inserted sentence ? (except creating
a
> new document of course...)

> TIA
> --
> -------------------------------
> Lorenzo Sandini
> Kirurgian Klinikka
> Kansanterveyden Tutkimuslaitos
> Kuopion Yliopisto
> Tieoteknia - OSTPRE
> 70200 Kuopio
> FINLAND
> --------------------------

> Hi Lorenzo,

> Time to jump in to the deep end.

> I would suggest using a UserForm for this purpose.

> First take a look at "How to create a UserForm" at

> http://www.mvps.org/word/FAQs/Userforms/CreateAUserForm.htm

> Then, instead of putting textboxes on the userform, use a checkbox for
each
> sentence, and put the sentence as the caption in an adjacent label.

> Then in the CommandButton Click event code, use the following

> If CheckBox1.Value = True Then
>     ActiveDocument.Bookmarks("Sentence1").Range.InsertBefore
Label1.Caption
> End If

> etc for each CheckBox

> This is assuming that you place Bookmarks in the template named Sentence1,
> ... Sentencen  for each possible sentence and that caption of label1,
> coincides with what you want for Sentence1.

> Please post any follow-up or new questions to the Newsgroups so that
others
> may benefit therefrom or contribute thereto.

> Hope this helps,
> Doug Robbins - Word MVP


> > Hi,

> > I am a complete newbie in the world of macros so please don't laugh  :o)

> > What I am trying to do is to write some standard report for each patient
> who
> > comes for a medical visit (a specialized bone ultrasound measuring
> method).
> > In this report, I would like to insert a few comments about the medical
> > history of my patients, and these comments are the answers to some very
> > basic questions.

> > I already did 10 short macros who insert a string of text, and then I
made
> a
> > new toolbar with a button for each of them, so by clickng on them one by
> > one, I build my report. The various sentences that are inserted with
each
> > macro are simple so they can be put one after another and the resulting
> text
> > is quite acceptable, no matter in what order I put them.

> > I was hoping to find a way of doing it like this : I would have some
place
> > in the page where I would just put a cross in checkboxes for the
sentences
> I
> > want in my report, then I would use one macro to build all the text from
> the
> > selected checkboxes. The checkboxes would be hidden (not printed), only
> used
> > by the physician or technician who writes the report.

> > Any idea about how to do this ?

> > TIA
> > --
> > -------------------------------
> > Lorenzo Sandini
> > Kirurgian Klinikka
> > Kansanterveyden Tutkimuslaitos
> > Kuopion Yliopisto
> > Tieoteknia - OSTPRE
> > 70200 Kuopio
> > FINLAND
> > --------------------------



Tue, 16 Sep 2003 19:41:35 GMT  
 recalling a userform and resetting document
Doug,

The code you sent is just absolutely perfect for what I am doing. If I would
go further in fine-tuning, I would put a very short Caption to the
textboxes, just a hint to the sentence I want to insert. I would then make
the following modification to your code :

Quote:
> If CheckBox1.Value = True Then
>     ActiveDocument.Variables.Add Name:="Test1", Value:=CheckBox1.Caption

becomes :

Quote:
> If CheckBox1.Value = True Then
>     ActiveDocument.Variables.Add Name:="Test1", Value:="This is the

sentence I want to insert if checkbox1 is checked "

So instead of inserting the "CheckBox1.Caption", I could insert any sentence
I want, and still keep the userform to a reasonable size, since my captions
would have to be too long.

Once again, thank you  :o)
--
----------------------------------------------
Lorenzo Sandini
Kirurgian Klinikka
Kansanterveyden Tutkimuslaitos
Kuopion Yliopisto
70200 Kuopio
SUOMI-FINLAND
------------------------------------------------

Quote:
> Hi Lorenzo,

> In this case it might be better to take a slightly different approach
using
> document variables instead of bookmarks to hold the information

> The following is the code that you would use in the userform

> Private Sub CommandButton1_Click()
> '    Delete any existing variables from the document
> Dim avariable As Variable
> For Each avariable In ActiveDocument.Variables
>     avariable.Delete
> Next avariable
> '    Create a variable for each check box.  If the check box is checked,
> '    the variable is loaded with the sentence contained in the caption of
> '    the check box.  If it is not checked, the variable is left empty.
> If CheckBox1.Value = True Then
>     ActiveDocument.Variables.Add Name:="Test1", Value:=CheckBox1.Caption
> Else
>     ActiveDocument.Variables.Add Name:="Test1", Value:=" "
> End If
> If CheckBox2.Value = True Then
>     ActiveDocument.Variables.Add Name:="Test2", Value:=CheckBox2.Caption
> Else
>     ActiveDocument.Variables.Add Name:="Test2", Value:=" "
> End If
> UserForm1.hide
> ActiveDocument.Fields.Update
> End Sub

> Private Sub UserForm_Activate()
> '    Clear the check boxes on loading the form
> CheckBox1.Value = False
> CheckBox2.Value = False
> End Sub

> In place of bookmarks, insert  Docvariable fields in your document (select
> Fields from the Insert menu, then select the Document Automation category
> and select DocVariable and then enter the name of the variable inside
quote
> marks, such as DOCVARIABLE "Test1"

> Please post any follow-up or new questions to the Newsgroups so that
others
> may benefit therefrom or contribute thereto.

> Hope this helps,
> Doug Robbins - Word MVP



Fri, 19 Sep 2003 17:16:05 GMT  
 recalling a userform and resetting document
Hi Lorenzo,

The reason that I had suggested using the caption was because I thought you
wanted the user to see what it was that they were selecting.

Please post any follow-up or new questions to the Newsgroups so that others
may benefit therefrom or contribute thereto.

Hope this helps,
Doug Robbins - Word MVP

Quote:
> Doug,

> The code you sent is just absolutely perfect for what I am doing. If I
would
> go further in fine-tuning, I would put a very short Caption to the
> textboxes, just a hint to the sentence I want to insert. I would then make
> the following modification to your code :

> > If CheckBox1.Value = True Then
> >     ActiveDocument.Variables.Add Name:="Test1", Value:=CheckBox1.Caption

> becomes :

> > If CheckBox1.Value = True Then
> >     ActiveDocument.Variables.Add Name:="Test1", Value:="This is the
> sentence I want to insert if checkbox1 is checked "

> So instead of inserting the "CheckBox1.Caption", I could insert any
sentence
> I want, and still keep the userform to a reasonable size, since my
captions
> would have to be too long.

> Once again, thank you  :o)
> --
> ----------------------------------------------
> Lorenzo Sandini
> Kirurgian Klinikka
> Kansanterveyden Tutkimuslaitos
> Kuopion Yliopisto
> 70200 Kuopio
> SUOMI-FINLAND
> ------------------------------------------------


> > Hi Lorenzo,

> > In this case it might be better to take a slightly different approach
> using
> > document variables instead of bookmarks to hold the information

> > The following is the code that you would use in the userform

> > Private Sub CommandButton1_Click()
> > '    Delete any existing variables from the document
> > Dim avariable As Variable
> > For Each avariable In ActiveDocument.Variables
> >     avariable.Delete
> > Next avariable
> > '    Create a variable for each check box.  If the check box is checked,
> > '    the variable is loaded with the sentence contained in the caption
of
> > '    the check box.  If it is not checked, the variable is left empty.
> > If CheckBox1.Value = True Then
> >     ActiveDocument.Variables.Add Name:="Test1", Value:=CheckBox1.Caption
> > Else
> >     ActiveDocument.Variables.Add Name:="Test1", Value:=" "
> > End If
> > If CheckBox2.Value = True Then
> >     ActiveDocument.Variables.Add Name:="Test2", Value:=CheckBox2.Caption
> > Else
> >     ActiveDocument.Variables.Add Name:="Test2", Value:=" "
> > End If
> > UserForm1.hide
> > ActiveDocument.Fields.Update
> > End Sub

> > Private Sub UserForm_Activate()
> > '    Clear the check boxes on loading the form
> > CheckBox1.Value = False
> > CheckBox2.Value = False
> > End Sub

> > In place of bookmarks, insert  Docvariable fields in your document
(select
> > Fields from the Insert menu, then select the Document Automation
category
> > and select DocVariable and then enter the name of the variable inside
> quote
> > marks, such as DOCVARIABLE "Test1"

> > Please post any follow-up or new questions to the Newsgroups so that
> others
> > may benefit therefrom or contribute thereto.

> > Hope this helps,
> > Doug Robbins - Word MVP



Fri, 19 Sep 2003 19:48:21 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Variable(s) Reset by Showing 2nd UserForm on top 1st UserForm

2. Recall a userform

3. recalling items from userform.listbox in other procedure

4. Resetting variables in userform

5. Resetting objects in userform

6. Reset a UserForm

7. Resetting userform controls en mass

8. Resetting default document style

9. resetting margins and also showing pages in document

10. Resetting Blank Document default


 
Powered by phpBB® Forum Software © phpBB Group