Unlock Statement

Syntax

Unlock [#]filenumber[, recordrange]

filenumber

Use: Required

Data Type: Integer

Any valid file number.

recordrange

Use: Optional

Data Type: Long

A range of records.

The syntax for the recordrange argument is:

recnumber | [start] To end

recnumber

Use: Required

Data Type: Long

The record or byte number to unlock.

start

Use: Optional

Data Type: Long

The first record or byte number to unlock.

end

Use: Required

Data Type: Long

The last record or byte number to unlock.

Description

Use the Unlock statement in situations where more than one part of your program may need read and write access to the same data file. The Unlock statement removes a lock placed on a section or the whole file that was locked with the Lock statement.

Rules at a Glance

  • Records and bytes in a file are always numbered sequentially from 1 onwards.

  • To unlock a particular record, specify its record number and only that record is unlocked.

  • Use the Unlock statement omitting recnumber to unlock the whole file.

  • The Unlock statement unlocks an entire file opened in input or output (sequential) mode, regardless of the recordrangeargument.

  • If you omit the start argument in the recnumber syntax, Unlock unlocks all records from the start of the file to record or byte number end.

Programming Tips and Gotchas

  • You must take care to remove all file locks using the Unlock statement before either closing a file or ending the application; otherwise, you can leave the file in an unstable state. This, of course, ...

Get VB & VBA in a Nutshell: The Language now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.