FileAttr Function

Note: The function, method, object, or property described in this topic is disabled if the Microsoft Jet Expression Service is running in sandbox mode, which prevents the evaluation of potentially unsafe expressions. For more information on sandbox mode, search for "sandbox mode" in Help.

Returns a Long representing the file mode for files opened using the Open statement.

Syntax

FileAttr ( filenumber , returntype )

The FileAttr function syntax has these arguments:

Argument

Description

filenumber

Required. Integer. Any valid file number.

returntype

Required. Integer. Number indicating the type of information to return. Specify 1 to return a value indicating the file mode. On 16-bit systems only, specify 2 to retrieve an operating system file handle. returntype 2 is not supported in 32-bit systems and causes an error.

Return Values

When the returntypeargument is 1, the following return values indicate the file access mode:

Mode

Value

Input

1

Output

2

Random

4

Append

8

Binary

32

Example

Note: Examples that follow demonstrate the use of this function in a Visual Basic for Applications (VBA) module. For more information about working with VBA, select Developer Reference in the drop-down list next to Search and enter one or more terms in the search box.

This example uses the FileAttr function to return the file mode and file handle of an open file. The file handle is returned only on 16-bit systems; on 32-bit systems, passing 2 as a second argument generates an error.

Dim FileNum, Mode, Handle
FileNum = 1 ' Assign file number.
Open "TESTFILE" For Append As FileNum ' Open file.
Mode = FileAttr(FileNum, 1) ' Returns 8 (Append file mode).
Handle = FileAttr(FileNum, 2) ' Returns file handle.
Close FileNum ' Close file.
Share Facebook Facebook Twitter Twitter Email Email

Was this information helpful?

Great! Any other feedback?

How can we improve it?

Thank you for your feedback!

×