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

Saving Grid Values To Global Variables Problem

Status
Not open for further replies.

TheFoxMan

Programmer
Jun 11, 2002
6
US
I am having a problem saving grid column vales to global variables and using these variable to locate a record for edit. I have a form with a grid which displays the correct records available for edit. The user selects the record to edit from the grid and presses a edit button. In the click property of the edit button I save the grid values to global variables and then do a locate. The problem is that the first time I go thru this routine it workd correctly, but once I return to the grid and select another record the global variable values are never changed. I am at a loss as to how I am not getting the correct values. Any Ideas?
 
Instead of using Global variables, why don't use Form Properties instead..

You can create form properties and everytime in the Activate event, reset them to:

Thisform.Property1 = ' '
Thisform.Property2 = ' '
etc...

in the click event of the grid

if !eof()
thisform.Property1 = Table.Name
thisform.Property2 = Table.AcctNum
etc.. (whatever you want to load)
else
return
endif

and if you need to return any value to another form or pass it as param

in the unload event of the form:
return this.Property1 && or any other property that you have created!

Please let me know if this helped you :)

Tekno
Wireless Toyz
Ypsilanti, Michigan
 
TheFoxMan
Save your grid properties in the Column's comment.
Store this.column1.width to this.column1.comment && for example

 
What is the code you're using to save the fields to the global variables?

Perhaps the wrong table is selected after the first edit? Try issuing a direct "SELECT MyTable" command when the Edit button is pressed.

Ian
 
Here is the code that is executed (from the Click Activity for the Edit Button on the Grid) to save the grid values. It works correctly the first time thru and then the values never get changed after that even tho a new record is selected from the grid.


* Get The current trip number.
goMessage.Number = thisform.pfMain.pActivity.Trip_log1.grdTripLog.Column9.text1.value

* Get the current move number.
goMessage.Amount = thisform.pfMain.pActivity.Trip_log1.grdTripLog.Column8.text1.value

do form edit_activity.scx

Then this code is executed in the Activity Event of the Edit_Activity form.

set filter to tp_trip_num = goMessage.Number and tp_move_num = goMessage.Amount

* Activate the filter
go top

In the Unload Activity this code is executed.

set filter to

go top

Hope this helps..


 
Rather than grabbing the text control's Value property, try grabbing the table fields directly:
[tt]
* Get The current trip number.
goMessage.Number = triplog.number

* Get the current move number.
goMessage.Amount = triplog.amount

do form edit_activity.scx
[/tt]
I'm guessing as to the field names, but you should get the idea.

Hope that helps,

Ian
 
I will try that but I have another question. Isn't the grid the result of a SQL query against the table and not the table itself. What I am asking I think is that the user has selected a record from the grid and not the table. I don't think I am pointing to that record in the table.
 
That depends on your RecordSourceType property. If it is set to 2-Alias, then it is pointing directly to the alias itself. If that alias is an open table, then it is pointing directly to the table, and the record pointer will move with the grid cursor.

SQL is only used if you specify for VFP to do so.

Ian
 
It is SQL that is being used. I will not beable to use field names instead of grid names value.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top