Specify filename – document naming

Having the created document automatically saved is very convenient:

building your document naming expression

Note before actually using the automated naming feature, make sure you know which are the document naming standards that apply to your organization.

If there are none, and you are free to decide yourself, you may want to read Document naming conventions (unimelb.edu.au) as an example.

In the following I will explain how in the document creation process wizard you can specify how the document will be named:

Composing the filename using VBA code

The document naming will be done using a line of code which concatenates and transforms the required data elements. In the VBA code generated on completion of the wizard there will be a line like this:


strFileName = ReplaceIllegalCharacters(ControlValue(![CustomerID]), "_")  & _
ReplaceIllegalCharacters(ControlValue(![Invoice Date], Format:="yymmdd"), "_")

In this example we see a couple of function calls: ReplaceIllegalCharacters and ControlValue:

ReplaceIllegalCharacters

This function replaces all characters which are not acceptable to the file system by a character – here the underscore (_), but you may also choose empty string (“”).

ControlValue

In the above there are two calls to the ControlValue function. In the first call it picks up the display value of the CustomerID control on the form which shows the name of the company.

Note: getting the name of the company could of course have been implemented differently, such as having an extra text control specifically for the name.

The second call shows the use of the Format argument whose expression makes the name accessible for sorting on date which may be useful.

Extending and improving the naming expression

At any point, in the Code text box in the wizard or in the generated VBA code, you can adapt the code. For example, you may decide to


strFileName = "invoice" & ControlValue(![CustomerID], UseDisplayValue:=False), Weekday()

strFileName = ReplaceIllegalCharacters(ControlValue(![CustomerID])  & _
                ControlValue(![Invoice Date], Format:="yymmdd"), "_")

strFileName = ReplaceIllegalCharacters(ControlValue(![CustomerID]), "_") & _
                  ControlValue(![Invoice Date], Format:="yymmdd")