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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

unexpected record is out of range in a grid

Status
Not open for further replies.

Nifrabar

Programmer
Mar 16, 2003
1,343
NL
Hi!
I'm having a dataform that is driven by view1.
There's another parametrized view (view2) which populates a grid.
My skip method always first selects view1 prior to actual do skip command.

Once the grid has focus and I do a skip which results in empty view2 (nothing to display from view2 in the grid) than there pops up an error message telling record is out of range. That error is there after a refresh of the form.
I found a solution by , prior to do the refresh, giving a dummy textbox focus.

Q1 is the error which popped up to overcome?
Q2 if not; I will find out what control of the grid (i.e. which column) has focus. Than set focus to a dummy textbox, refresh the form and than set focus back to the gridcolumn.

Is this a good way to proceed?

-Bart
 
This is actually what I would expect to happen. When a grid has focus it automatically selects the work area of its recordsource - in this case View2. Instead of trying to select View1 and skip, use the IN cluase in your command:

SKIP 1 IN View1

That should work even when the grid's recordsource is the current work area.

----
Andy Kramek
Visual FoxPro MVP
 
Andy,
I tried but same error.
This is the code in my skipmethod.
Any strange in it?
-Bart

Code:
* skipforward
LPARAMETERS tBottom
LOCAL llOK, lnOldSelect, lcPrimTable
llOK = .T.
WITH this
	IF !thisform.lCanNavigate
		RETURN
	ENDIF
	.LockScreen = .T.

		llOK = .SavePendingChanges()
		* to adapt code here once llok = .f. (SAVE OR REVERT failed)
		
		.Refresh()

		lnOldSelect = SELECT()
		IF !EMPTY(.cPrimairytable)
			.beforeskip()
			
			SELECT (.cPrimairyTable)

			
			IF tBottom
				GO BOTTOM 
			ELSE 
				IF !EOF()	
					SKIP  IN (.cPrimairyTable)
				ENDIF 
			ENDIF 

			IF EOF()
				GO Bottom
				=.message(MSG_LAST_REC,WHITE,BLACK,.Left,.width,.height)
			ENDIF

			.afterskip()	

			.refreshform()
		ENDIF 
		SELECT (lnOldSelect)
		
	.LockScreen = .F.
		
ENDWITH
 
Bart,

Run the application in the development environment, with no error-hanlder in force (no ON ERROR command). When the error occurs, click Suspend. That will take you into the debugger.

You can then check to see which command caused the error, which work area was selected, and what record the program was trying to navigate to.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Hi Mike,
Thanks for your suggestion.
In normal I always heve no error handles when in development environment. By that I already found that the error rise while executing the .refreshform()
I'm unfamilair how to find in the debugger which table was tried to navigate in and so causing the error. Could you pls. point me to that?
-Bart
 
Just put alias() in the debugger watch window to see the currently active alias.
 
Bart,

I already found that the error rise while executing the .refreshform()

What code have you got in the Refreshform method?

I'm unfamilair how to find in the debugger which table was tried to navigate in and so causing the error.

Go to the Watch window. In the box labelled Watch, enter a valid VFP expression and press Enter. In the space below, you will see the current value of the expression. To find which table is selected, the expression would be ALIAS(). To find the record number, you would enter RECNO(). And so on.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
!EMPTY(.cPrimairytable)"
I am sure you know, this is just checking if there is a table name in this property and Not whether there are any records...
Whats the code in Refreshform() ?
 
Hi!
Imagincorp: yes, it's meant to be sure the property has a value.

Mike and Markros : thanks for pointing me for that use of the debugger.
I'm going to further try to debug now.

I used the method from '1001 things'

-Bart
Code:
*RefreshForm
*** This method wraps the call to the Refresh method inside
*** a LockScreen and includes calls to Before and After Hooks
LOCAL llOk
WITH This
    .LockScreen = .T.
    *** Call Before Hook
    llOk = .BeforeRefresh()
    IF llOk
        *** Before was OK, so call Refresh
        .Refresh()
        *** And then the After Hook
        .AfterRefresh()
    ENDIF
    .LockScreen = .F.
ENDWITH

RETURN llOk
 
Bart,

And is there any code in your .BeforeRefresh or .AfterRefresh?

It seems odd that you're getting "record out of range" on commands that are not moving the record pointer. In fact, the only line that could give that message is your SKIP IN (.cPrimairyTable), as far as I can see.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Hello Mike,
No I didnot put in those methods. As you know these hooks are included by the authors of 1001 things.

Keep in mind that the recordsource of the view is a parametrized view. The strange thing is that the error only occurs once I clicked in the grid prior to skip the 'main' view.
-Bart
 
Bart,

The strange thing is that the error only occurs once I clicked in the grid prior to skip the 'main' view.
[

Ah, now that's interesting.

Did you know that clicking on grid could cause VFP to select the work area of the grid's underlying cursor? I'll bet that's the cause of the problem.

I don't know what the official workaround is. No doubt others will tell you.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Mike,
Thanks again for sharing your time with my problem.
As you read back; Andy Kramek pointed to the effect of clicking in a grid..
As my workaround now is to set focus to a dummy textbox prior to do the refreshform I think I have to work-out that workaround.
Could you help me how I can find (by code) the current-selected column from a grid? And how to set focus to that column?
-Bart
 
Hi Bart

>>Could you help me how I can find (by code) the current-selected column from a grid? And how to set focus to that column?

When the grid has focus you can read the ActiveRow and ActiveColumn properties. Then you can use ActivateCell() method to set focus to a particulatr Row/Column if not already correct.

NOTE: ActiveRow/ActiveColumn ONLY have non-zero values when the grid has focus, so you must set focus back to the grid before tryng to use them.


----
Andy Kramek
Visual FoxPro MVP
 
Hi Andy,
Thanks for your reply but I should like to find by using code the gridcolumn having focus.
Than I set focus to a dummy textbox and do the formrefresh.
Thereafter set focus back to grid.

In fact ; more general; currentcontrol must be saved; set focus to dummy textbox before refreshform and thereafter set focus back to saved 'currentcontrol'.
Most I can relaize but only getting currentcontrol from grid and set back focus to that I don't know th eexact syntax.

-Bart
 
Set the grid’s Allow Add New property to .T.. Then Before displaying the grid, in the grids or forms Init, insert a record i.e.
IF recount(“Paratermized View Name”) < 1
Insert into….
*Insert only the relation field.
endif
In form’s Query unload check if any values have been entered by the user, if not Delete the record just created.

This should solve the problem…. I think unless there are other factors involved
 
Imaginecorp,
Thanks for your suggestion.
I am going to study this solution for I don't directly oversee any consequences (as I am also having an alert which pops up the 'save new record' message).


Dear all,
Further suggestions will be replied on by me at the end of august as my vacation (almost 4(!) weeks) starts tomorrow.
 
>>Thanks for your reply but I should like to find by using code the gridcolumn having focus.
Than I set focus to a dummy textbox and do the formrefresh.
Thereafter set focus back to grid.

But if the grid already has focus then you can simply read the ActiveRow/ActiveColumn properties and save them to a form property.

Then send your focus to the dummy text box and when ready use ActivateCell() to set focus back to the correct location. Isn't that what you want to do? If not, then I totally musunderstanding what you are trying to achieve.



----
Andy Kramek
Visual FoxPro MVP
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top