[AccessD] auto save in word

Stuart McLachlan stuart at lexacorp.com.pg
Sun May 23 17:35:07 CDT 2004


On 23 May 2004 at 23:03, Pedro Janssen wrote:

> Hello Group,
> 
> 
> After merging data from access with use of properties in word, i use
> the code below to save a word document in a certain directory with the
> name; Bezoekrapport("BezoekrapportID").doc, by clicking a button. When
> the documentname in the directory already excist i would have the name
> changed to  Bezoekrapport("BezoekrapportID")_1.doc or
> Bezoekrapport("BezoekrapportID")_2.doc   etc, etc. Can this been done? 
> 
> 
Just check for the existence of a file with the name and suffix and 
increment it if necessary in a loop until you find a unique one.

Dim flgSaved as Boolean
Dim strSuffix as String
flgSaved = False
strSuffix = ""

Do
   strFilename = 
Dir$("W:\WerkbrievenOpslag\Bezoekrapport\Bezoekrapport" _ 
   & strFileNamePart & "_" & strSuffix & ".doc" 
   If Dir$(strFilename) > " "  Then        ' File exists
       strSuffix = str$(val(strSuffix)+1) ' use a larger suffix
   Else
      flg Saved = True
      ActiveDocument.SaveAs FileName:=strFilename       
      flgSaved = True
   End If
Loop Until flgSaved


 
-- 
Lexacorp Ltd
http://www.lexacorp.com.pg
Information Technology Consultancy, Software Development,System 
Support.






More information about the AccessD mailing list