Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / July 2005

Tip: Looking for answers? Try searching our database.

Problem Incrementing Form Number/Name

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
cdub - 25 Jul 2005 22:23 GMT
Hi, I have a form that uses a text file to keep track of the form number
automatically inserted in a form field.  Then, when the user clicks on the SAVE
and Print button, it saves it with the standard name and form number and prints
it.  It works pretty well except:

1.  Some users refuse to click the SAVE and PRINT button and use the toolbar to
print, save and exit.  The number in the text file is incremented but there is
no matching document in the designated file folder.

2.  The form is incremented before it is saved so if a user changes their mind
and exits the form, the text file is still incremented and there is no
corresponding file in the file folder.

I need to cause the number in the text file to be incremented only if the user
uses the SAVE and Print button and force the user to use the SAVE and Print
button instead of the toolbar.

I'm only trying to edit this form and do not know much VBA at all.  Any help
would be appreciated.

Thanks,
Connie
Jean-Guy Marcil - 26 Jul 2005 14:18 GMT
cdub was telling us:
cdub nous racontait que :

> Hi, I have a form that uses a text file to keep track of the form
> number automatically inserted in a form field.  Then, when the user
[quoted text clipped - 16 lines]
> I'm only trying to edit this form and do not know much VBA at all.
> Any help would be appreciated.

It seems you must check for two states before taking any action, i.e. the
document must be saved and printed.
When printing, you can check if the document has been saved or not. Whereas,
if you save, there is no direct way of checking if the document has been
printed, although you can try something like this:

First of all,  to catch whatever the user does regarding saving/printing,
create four macros called as follows:

Sub FileSave()
Sub FileSaveAs()
Sub FilePrint()
Sub FilePrintDefault()

These sub will intercept any save/print command, whether initiated by a
button, a menu or the built in shortcuts. This way you do not need any
custom SAVE or PRINT button.

Now, in each sub, try code like this:

'_______________________________________
Public HasBeenPrintedOnce As Boolean
'_______________________________________
Sub FileSave()

If ActiveDocument.Path = "" Then
   FileSaveAs
   Exit Sub
End If

ActiveDocument.Save

If HasBeenPrintedOnce Then
   SpecialCodeIfDocSavedAndPrnted
End If

End Sub
'_______________________________________

'_______________________________________
Sub FileSaveAs()

MsgBox "FileSaveAs"

If Dialogs(wdDialogFileSaveAs).Show = 0 Then
   Exit Sub
End If

If HasBeenPrintedOnce Then
   SpecialCodeIfDocSavedAndPrnted
End If

End Sub
'_______________________________________

'_______________________________________
Sub FilePrint()

If Dialogs(wdDialogFilePrint).Show = 0 Then
   Exit Sub
End If

HasBeenPrintedOnce = True

If ActiveDocument.Saved Then
   SpecialCodeIfDocSavedAndPrnted
End If

'_______________________________________

'_______________________________________
Sub FilePrintDefault()

ActiveDocument.PrintOut

HasBeenPrintedOnce = True

If ActiveDocument.Saved Then
   SpecialCodeIfDocSavedAndPrnted
End If

End Sub
'_______________________________________

'_______________________________________
Sub SpecialCodeIfDocSavedAndPrnted()

   MsgBox "Doing something here"

End Sub
'_______________________________________

This way you execute your code when saving only if the document has been
printed, or when printing only if the document has been saved. You may want
to add code to make sure that our code executes only once. You could add
another global variable like:
Public HasBeenPrintedOnce As Boolean, let's say
   Public CodeEexecuteOnce As Boolean
and set it to true whenever your special code executes.
In all four subs, check for that variable value before calling the special
code.

There is a "hole" in this though: If a user quits without saving, then Word
displays a prompts asking if the document should be saved or not, if they
decide to save at that point, and the document has never been saved, but
printed once, then the Save Subs will not be called, and you special code
will not execute. One way around this is to force the user to save when
printing if the document has never been saved (i.e. when < If
ActiveDocument.Path = "" >).
Then you would not have this problem. To do this, call FileSaveAs from the
Print Subs if the document has never been saved and do not allow the user to
"not save" if they have printed.

There might be an easier way of doing all this, but right now this is all
can see!

Signature

Salut!
'_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.