# Use of Inquire to find Next record

**URL:** <https://fortran-lang.discourse.group/t/use-of-inquire-to-find-next-record/2292>\
**Category:** Help\
**Created:** [November 17, 2021, 10:39am UTC](https://fortran-lang.discourse.group/t/use-of-inquire-to-find-next-record/2292 "2021-11-17T10:39:14Z")\
**Posts on this page:** 1\
**Showing post:** 12

<div class="post-metadata">

**Author:** ![mecej4](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/mecej4/32/855_2.png) [@mecej4](https://fortran-lang.discourse.group/u/mecej4)\
**Post date:** [November 18, 2021, 10:42am UTC](https://fortran-lang.discourse.group/t/use-of-inquire-to-find-next-record/2292/12 "2021-11-18T10:42:11Z")

</div>

This forum does not have a provision for attaching files to posts. That rule does not depend on a moderator.

To attach files, please follow the procedure that you used in your previous thread, [Reading data into direct access files - #37 by miramar46](https://fortran-lang.discourse.group/t/reading-data-into-direct-access-files/2079/37) .

The effect of a NEXTREC = clause in an INQUIRE statement depends on what has been done with the file earlier in the program. Here is the wording from the 2018 standard:

> The scalar-int-variable in the NEXTREC= specifier is assigned the value n + 1, where n is the record number of the last record read from or written to the connection for direct access. If there is a connection but no records have been read or written since the connection, the scalar-int-variable is assigned the value 1. If there is no connection, the connection is not for direct access, or the position is indeterminate because of a previous error condition, the scalar-int-variable becomes undefined.

Perhaps, you misunderstand the role of the NEXTREC= clause in an INQUIRE statement. It does not **set** the record number for the subsequent READ/WRITE statement; it **get** s the anticipated record number; the variable after the ‘=’ can be undefined, or have any value whatsoever, prior to executing the INQUIRE statement; when the INQUIRE is executed, that value will be overwritten by the record number that will be used by the next READ/WRITE statement.

---

_[View the full topic](https://fortran-lang.discourse.group/t/use-of-inquire-to-find-next-record/2292)._
