totn Access Functions

MS Access: SetAttr Statement

This MSAccess tutorial explains how to use the Access SetAttr function with syntax and examples.

Description

The Microsoft Access SetAttr statement allows you to set the attributes of a file.

Syntax

The syntax for the SetAttr statement in MS Access is:

SetAttr path, attributes

Parameters or Arguments

path
The path to a file that you wish to set the attributes for.
attributes

The attributes that you'd like to set for the file. Attributes can be the following values:

VB Constant Value Explanation
vbNormal 0 Normal (default)
vbReadOnly 1 Read-only
vbHidden 2 Hidden
vbSystem 4 System file
vbArchive 32 File has been changed since last backup
vbAlias 64 File name is an alias (Macintosh only)

Returns

The SetAttr function does not return a value, but rather sets the attributes of a file.

Applies To

The SetAttr statement can be used in the following versions of Microsoft Access:

  • Access 2019, Access 2016, Access 2013, Access 2010, Access 2007, Access 2003, Access XP, Access 2000

Example

Let's look at how to use the SetAttr function in MS Access:

SetAttr "C:\instructions.doc", vbNormal
Result: Sets the file to Normal

SetAttr "C:\instructions.doc", vbReadOnly + vbHidden
Result: Sets the file to ReadOnly and Hidden

Example in VBA Code

The SetAttr statement can be used in VBA code in Microsoft Access.

For example:

SetAttr "c:\Test\Doc1.doc", vbReadOnly + vbHidden

In this example, the file called Doc1.doc (found in the c:\Test\ directory) would now be set to a ReadOnly, Hidden file.