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!

Results not shown in Grid inside a Form 1

Status
Not open for further replies.

SitesMasstec

Programmer
Sep 26, 2010
523
Brasil
Dear collegues:

Once more I am here to ask your help for a single question:

Grid4a_ofjlub.jpg


In the figure above I wish, after typing the text FAR in the TextBox, all the items from the table TACO.DBF beginning with "FAR" to be shown (see 1).
But the result (see 2, -- "Result") shows nothing... in spite of the fact that TEMPTACO.DBF is populated with the desired rows after the user press <enter> (see figure bellow) !

Grid5_y5mmmq.jpg


Note that when I execute the form it shows the result I would like to have in the session immediately before (Content from TEMPTACO.DBF) !


I have:
Grid6_qrxkx8.jpg


Form, DataEnvironment is TEMPTACO.DBF


Form, KeyPress event is:
Code:
IF nKeyCode=13 AND nShiftAltCtrl=0 
	Parte=ALLTRIM(ThisForm.QualTaco.Value)
	LenParte=LEN(Parte)

	IF LenParte=0
		thisform.Release
	ENDIF

	
    SELECT TACODESCR AS WTACODESCR, TACOCALOR AS WTACOCALOR;
 	FROM TACO ;
 	WHERE UPPER(Parte) = UPPER(LEFT(TACO.TACODESCR,LenParte)) ;
 	INTO TABLE TEMPTACO

	thisform.Grid1.Refresh
ENDIF

Grid1, DblClick:
Code:
thisform.Release


Thank you,
SitesMasstec
 
>INTO TABLE TEMPTACO

This is what you should never do with a table you display in a grid. You recreate the DBF and though that means after the query everything is back, the grid "notices" this. The moment the DBF is destroyed before it is rebuild is the moment your grid becomes blank.

Do this instead:

Code:
ZAP IN TEMPTACO
INSERT INTO TEMPTACO ;
SELECT TACODESCR AS WTACODESCR, TACOCALOR AS WTACOCALOR;
 	FROM TACO ;
 	WHERE UPPER(Parte) = UPPER(LEFT(TACO.TACODESCR,LenParte))

There are some prerequisites for this:
1. TEMPTACO.DBF already exists
2. You have exclusive access to it.

A much better approach would NOT gnerate a permanent DBF file but a cursor. Also that will need to be kept for the grid to work, but everything you only want temporary does not need to go to hard drive.

Bye, Olaf.


 
Good, Olaf, I abandoned the hard drive here, as you advised:

thisform.Grid1.RecordSource = ""
SELECT TACODESCR, TACOCALOR FROM TACO ;
WHERE UPPER(Parte) = UPPER(LEFT(TACO.TACODESCR,LenParte)) ;
INTO CURSOR TEMPTACO
thisform.Grid1.RecordSource = "TEMPTACO"

No more temporary table, but cursor instead.

And it is working fine now. Thank you.




Thank you,
SitesMasstec
 
Also with a cursor it's advisable to use the ZAP and refill strategy.

In form init prepare the empty cursor:

Code:
SELECT TACODESCR, TACOCALOR FROM TACO WHERE .F. INTO CURSOR crsTEMPTACO READWRITE

In your keypress:
Code:
IF nKeyCode=13 AND nShiftAltCtrl=0 
	Parte=ALLTRIM(ThisForm.QualTaco.Value)
	LenParte=LEN(Parte)

	IF LenParte=0
		thisform.Release
	ENDIF

ZAP IN crsTEMPTACO
Insert Into crsTEMPTACO;
SELECT TACODESCR, TACOCALOR FROM TACO ;
WHERE UPPER(Parte) = UPPER(LEFT(TACO.TACODESCR,LenParte))

	thisform.Grid1.Refresh
ENDIF

When working this way the cursor stays, the ZSAP only empties it. There is no need to temporary unbind the RecordSource and that only is a half solution anyway for several reasons too long to state right now.

Bye, Olaf.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top