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!

Re-doing a Query in a grid ! 1

Status
Not open for further replies.

Stagmotor

Programmer
Dec 8, 2000
10
US
I want to view different queries in a Grid.
In the LOAD method of a FORM, I have the following SQL code to display data in a grid.

SELECT cutomer.name,order.invno ;
FROM customer,orders ;
WHERE customer.custid_no = orders.custid_no and customer.name = "FRANK" (or a variable) ;
ORDER BY customer.datebilled ;
INTO CURSOR mycursor

I set the grid RecordSourceType property to 1-Alias and
RecordSource to mycursor. The grid SHOWS THE DATA FINE.

HOWEVER, in the Click Method of a command button in the form, to query a different name I tried the following:

SELECT cutomer.name,order.invno ;
FROM customer,orders ;
WHERE customer.custid_no = orders.custid_no and ; customer.name = "JOHN" (or a variable) ;
ORDER BY customer.datebilled ;
INTO CURSOR mycursor
Thisform.refresh

The grid goes blank and I can't view the results. Does anyone know why it does'nt work. Thanks

 
This is natural behavior although it seems a bit odd.

When the record source is set, the grid uses this record source. But when you build a new query, the recordsource is a different cursor although you have given it the same name. internally both cursors called MyCursor have a different identity. So to the grid the cursor that was first created does not exist anymore, so there is no recordsource to display.

A better way is to make a blank cursor and add and remove records iso doing a new query.

A nice way to handle this is to use a view, which is in fact also a kind of cursor, but doesn't give the mentioned unwanted effect.

Weedz (The Grassman)
veld4663@exact.nl

'It never hurts to help...' - Eek the cat.
 
When you rebuild the cursor, the grid loses the "connection" to the cursor. What normally works is to reset the recordsource to "" before the query, and then put it back to the cursor afterwards. e.g.

ThisForm.grid1.recordsource = ""
SELECT ... ;
INTO CURSOR mycursor
LOCATE && go top
ThisForm.grid1.recordsource = "mycursor"
ThisForm.refresh()

Rick
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top