Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Record is out of range

Status
Not open for further replies.

vfp4ever

Programmer
Oct 18, 2013
71
East Java
Hello,


I have another issue, this time regarding Column controls and their ControlSource. Specifically I have a Grid, whose Columns properties are redefined in a procedure ArrangeColumns every time it is needed (e.g. an Activate event, or when any table name changes). The underlying data is a set of multiple related tables, so that ControlSource values are something like "table1.Field1", "table2.Description" and so on. So far everything works fine as expected. A couple of fields have a ControlSource of type "table" + table9.SelectedYear + ".Amount", where table9.SelectedYear evaluates to something like "2018" (and table2018.dbf exists, of course, and is correctly opened and related before its use).

Now, things work well as long as the "parameter" (table9.SelectedYear) is initially selected, but when I change it in ArrangeColumns to something different (e.g. "2019") I hopelessly get a "Record is out of range" error. Tables are all open, variables are visible, I do not define extra private data sessions. What does this error mean?


Regards,
Dario
 
Hi Dario,

Make sure you do a requery and refresh for all fields on your form after changing the year.
I hope you don’t use a filter.

Regards, Gerrit
 
You asked what "Record is out of range" means. Well, the short answer is that the record that you are trying to access is beyond end-of-file.

To be frank, I'm not surprised you are running into trouble with this code. You are trying to change a control source dynamically to a field in different table: different from the tables in the relationship, and possibly with a different index order set (or no index order set) and probably with a different number of records.

"Record is out of range" often happens because the index does not match the table. That can happen if you are using a non-structural index (that is, an IDX rather than a CDX), or if the index has become corrupted. So that would be something to check.

But I think the best approach would be to re-think what you are doing. It's hard to give solid advice here because I don't know all the details of the problem, but my preferred approach would be to re-generate the underlying cursor each time you do the ArrangeColumns. Have a single cursor that contains all the data for the grid (that is, don't use a relationship), based on the table for the specified year. Before you re-generate it, set the grid's RecordSource to an empty string. After you have r-generated, set it to point to the cursor.

I'm not sure if that will give you what you want to achieve, but it is something to consider.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Thank you, Gerrit and Mike


With Gerrit's suggestion I managed to avoid the error as I set the ControlSource, but now something is messed up with the refresh. Unfortunately results often change simply by moving the same command further up or down within the same method, so it is a matter of patience and perseverance before anything works (and even then it is not completely clear why it does).

Mike, indeed the underlying data structure is quite complicated. While I am rather confident that my tables and relationships are opened and set correctly, I believe the different number of records in those dynamically changed control sources can upset VFP. Though I am sure there is a way to make it work: patience and perseverance!


Regards,
Dario
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top