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

How to release a cursor created with an SQL statment? 1

Status
Not open for further replies.

EzLogic

Programmer
Aug 21, 2001
1,230
US
I creat a cursor using sql
select .... whatever... into cursor TempCur

.. I do what I need to do with the cursor...

Now, when the form is being released, I need to close the cursor or release it.

I tried:
release cusor (but, It didn't work)
i tried:

Select TempCur
Use
I get an error message: "The Table cannot be accessed"

how can I handle such problem?
Thank you in advance! Ali Koumaiha -:)
 
Try:
If used("tempCur")
Use in TempCur
Endif
 
I tried that
and it is still saying
"Cannot access the selected table"

Plz help!!


Ali Koumaiha -:)
 
The help file says:

"You have attempted to select a table outside the 32K work area range or are attempting to reference a file variable in a table that is not open."

Can you post your exact query used to create the cursor, and the code your are using to close/release it?

Have you debugged to be certain that it is the attempt to close the cursor that is causing the error?
 
Thanx Marsh, here is the code:

* In the Init event of the code, I have the follwing to
* populate a combo box called 'cItem'

SELECT DISTINCT ACC.NO FROM ACC INTO CURSOR TempCur NOCONSOLE

thisform.cItem.RowSourceType = 6 && combo box
thisform.cItem.RowSource = 'TempCur.No'

Also, on the form, I have an Exit button
in the click event:

if used('TempCur')
use in TempCur
endif
ThisForm.Release()


/*****************************/
Maybe there is another way I could populate the combo, I tried the builder, but, that doesn't help, cuz, I need "NO DUPLICATE"

Plz let me know! Ali Koumaiha -:)
 
And I know the Cursor is still open, because, I put this code just before I release the form
Browse
and surely, it did display the content of the cursor

Ali Koumaiha -:)
 
Well, Marsh, I tried this and it worked:
if used('TempCur')
nSelect = Select() &&
Select (nSelect)
use
endif

is that Dangerous? I tried it, and all other alias/files are still open fine and no harm done. There might be something unforseen that could happend, but, I don't think so. Anyone with a suggestion on such usage, let me know!

thank you for your time and for your help! Ali Koumaiha -:)
 
That's dangerous -- it assumes that you really know what the currently selected work area is. If other data gets added to form, you might get unexpected reults.

Just also dawned on me what's really happening. Remove the code from the click button that is trying to close the cursor -- your grid still exists. Instead, put the code

If used("tempCur")
Use in TempCur
Endif

in the release method of the form.

 
I got it to work, thanx marsh!

What I ended up doing is creating a function in my main.prg

Func CloseCursor(cCurName)
if used(cCurName)
Select &cCurName
use
endif
Return


So, Everytime, I use a select sql statement and I use INTO cursor ..., After I realse the form
i do
CloseCursor('....')

:)
Wow, that was a little hectic@@@ Ali Koumaiha -:)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top