Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Tricky IF Statement (tricky for me!)

4 views
Skip to first unread message

humphrey...@gmail.com

unread,
Dec 18, 2007, 6:02:52 AM12/18/07
to
I currently have a document with a custom form that asks the user for
information then a print button at the bottom of the form which prints
the information.

The print button has VB which sets up the variables for the text boxes
on the form then more vb which places the results from the variables
onto an A4 sheet. The VB then prints the sheet and closes the document
without saving it (as it doesn't need saving after printing). It then
closes word. The two lines of code I use to achieve the two closures
are:

ActiveDocument.Close (wdDoNotSaveChanges)
Application.Quit

Here's the full code for the print button:

Private Sub PrintBtn_Click()

'sets variable for each txtBox on form, just to make it easer
vName = Form.txtName
vAmount = Form.TxtAmount
vAmount2 = Form.TxtAmount2
vFor = Form.TxtFor

'Goes to each field on form and sets results equal to variables
ActiveDocument.FormFields("bkName").Result = vName
ActiveDocument.FormFields("bkAmount").Result = vAmount
ActiveDocument.FormFields("bkAmount2").Result = vAmount2
ActiveDocument.FormFields("bkFor").Result = vFor

'Remove Form from screen
Form.Hide

'Prints the form
Selection.EndKey Unit:=wdStory
Application.PrintOut FileName:="", Range:=wdPrintCurrentPage,
Item:= _
wdPrintDocumentContent, Copies:=1, Pages:="",
PageType:=wdPrintAllPages, _
Collate:=True, Background:=True, PrintToFile:=False

'Closes document and Word
ActiveDocument.Close (wdDoNotSaveChanges)
Application.Quit

End Sub

It all works fine except that my dilemma is that if there are other
word documents open, it will go through the closure procedure
(obviously as I'm using Application.Quit) and it asks if you want to
save the other open documents before exiting (as word usually does
when you close word without saving first).

This is no big deal for me, but as this document is set up for
clients, I don't want to tell them to just press Yes to save the
document/s or Cancel to keep the document/s open and keep working on
them, as they are the type of client who will get confused and press
No instead and lose their work.

If I take out the application.quit code and if there are no other open
documents, then the client is left with an open session of word with
no document open. This would confuse my clients even more!!

So far I have made this document as smooth as possible for them - they
open it, fill in four fields, press print and it automatically prints
and closes (without saving). Simple! But if other documents are
already open...

Is there an IF Statement I can use (in place of the two 'close'
commands) that asks:

if
there are other open documents besides 'this one'
then
leave them open and close this one without saving it
else
close word without saving this document'
(ie ActiveDocument.Close (wdDoNotSaveChanges)
Application.Quit)
End If

I hope this makes sense.

Thanks

1

unread,
Dec 18, 2007, 6:09:22 AM12/18/07
to
Sorry for cross posting, but I might have initially put this in the
wrong group as I use word 2002 not 97.

If you can help, please reply to post in
microsoft.public.word.vba.general

1

unread,
Dec 18, 2007, 6:12:34 AM12/18/07
to

Frig I'm Dumb!!!

Original post in microsoft.public.word.word97vba:

Graham Mayor

unread,
Dec 18, 2007, 7:07:47 AM12/18/07
to
Do you mean like

ActiveDocument.Close (wdDoNotSaveChanges)
If Documents.Count = 0 Then
Application.Quit
End If

?

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org

1

unread,
Dec 18, 2007, 6:11:01 PM12/18/07
to
On Dec 18, 11:07 pm, "Graham Mayor" <gma...@REMOVETHISmvps.org> wrote:
> Do you mean like
>
> ActiveDocument.Close (wdDoNotSaveChanges)
> If Documents.Count = 0 Then
> Application.Quit
> End If
>
> ?
>
> --
> <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
> Graham Mayor - Word MVP
>
> My web sitewww.gmayor.com
> Word MVP web sitehttp://word.mvps.org
> <>>< ><<> ><<> <>>< ><<> <>>< <>><<>

Yes, exactly that.

Thank you! It works perfectly

1

unread,
Dec 18, 2007, 7:56:16 PM12/18/07
to
I have a new dilemma now. As this is a form to print cheques, my
client would like to know if they can type in a number and have it
automatically show up as text in dollars and cents somewhere else on
the page. At the moment they are typing the number (bkAmount) then
typing the text in another field (bkAmount2).

Therefore I somehow need to get rid of the Amount2 bookmark and
replace it with some conversion on the Amount bookmark somewhere else
on the page. I could use Ref bkAmount \* DollarText but this doesn't
give me the word "Dollars".

I have found the following macros but how do I run a macro to convert
a ref field automatically? The first macro assumes you're selecting
the text first.
<a href="http://groups.google.com.au/group/
microsoft.public.word.conversions/browse_thread/thread/
51f2a90faa801a4b/811c432a00eac36c?lnk=st&q=convert+number+to+text+in
+word+group%3A*word*#" Conversion of currency to english words in MS
word</a>

Or do I keep the Amount2 bookmark but instead of asking for the value
via the form (vAmount2) do I run some code that references the vAmount
figure, converts it and places it in bkAmount2?

Graham Mayor

unread,
Dec 19, 2007, 2:33:38 AM12/19/07
to
See the item Formatting cash amounts in words on my web page
http://www.gmayor.com/formatting_word_fields.htm

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com


Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

1

unread,
Dec 19, 2007, 6:58:36 PM12/19/07
to
On Dec 19, 6:33 pm, "Graham Mayor" <gma...@REMOVETHISmvps.org> wrote:

Wow! That's amazing. It worked. This should be referenced on Word
MVPS!!!

Thank you very much Graham for all your help!!

> See the item Formatting cash amounts in words on my web pagehttp://www.gmayor.com/formatting_word_fields.htm


>
> --
> <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
> Graham Mayor - Word MVP
>

> My web sitewww.gmayor.com
> Word MVP web sitehttp://word.mvps.org

0 new messages