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