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

Opening a form with a selected record from a grid 1

Status
Not open for further replies.

kstart

Programmer
Dec 25, 2004
21
US
This is a problem re-visited I have a better understanding but still am struggling with this issue.

I have two forms, the first is a data entry form named "Contacts." The second named "Change" is a form with a grid that shows all the contacts which is read only. I am trying to select a name in the grid and open the "contact" form with that record for editing or viewing purposes.

Following the example given in VFP9 help on "Passing Parameters to a form."

I made a new property named "firstname" for the "change" form.

The value of the property "firstname I left at .F. since I don't know what it means.

In the "change" form's Init event I put

[lPARAMETERS cString]
[THIS.firstname=cString]

In the double click event for the grid Text1 "which reflects the first name of the contact"

I placed [DO FORM change WITH THIS.Value]

The error shows that "No PARAMETER statement is found"
I obviously am missing some small detail,the idea, or some code as I do not know where the parameter statement is. I followed the VFP help example exactly I thought. ANy help would be appreciated.
 
kstart,

The way I read your message, you seem to be getting your forms back to front.

In your first paragraph you said:
I am trying to select a name in the grid and open the "contact" form with that record for editing or viewing purposes
but in the DoubleClick in the grid textbox you have
Code:
DO FORM [b]change[/b] WITH THIS.Value

If you want to call the Contact form from the grid on the Change form, then you need to have the LPARAMETERS statement in the Init event of form Contact.


Hope that helps,

Stewart
PS If you want to get the best response to a question, please check out FAQ184-2483 first.
 

Kstart,

I agree with Stewart that you should put the LPARAMETERS in the called form, but, the way I read your question, that's what you are doing. Although I think you confused the names of the forms when you said the Change form is the one with the grid.

Basically, the calling form should include the DO FORM ... WITH statement, and the Init of the called form should include the LPARAMETERS plus the code to store the value in a property.

Two other points:

- In your message, you placed square brackets round each line of code. I asssume you didn't do that in your actual code?

- Make sure the LPARAMETERS statement is the very first statement (apart from comments) in the Init.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

My sites:
Visual FoxPro (www.ml-consult.demon.co.uk)
Crystal Reports (www.ml-crystal.com)
 
Ok let me back up for a second. The form "contact" is the data entry form or the "called form." The form "change" is the form with the grid or the "calling form." in the called form, "contacts" I have made a new property called "firstname" and in the init for the "contacts" form I have:

LPARAMETERS cString, because the first name is a string
THIS.firstname = cString, because the example has this

on the calling form, "change" I have in the dbl click event of texti "the first name of the contact person's name":

DO FORM contacts WITH this.value

And I did not use [] in the actual code,


Just as you two suggested. Now I have no error about the parameter statement but it opens the contact form everytime with the value for the first record no matter which record in the grid I doubleclick.
 
it opens the contact form everytime with the value for the first record no matter which record in the grid I doubleclick.

It sounds as though you've got no mechanism for telling the called form which record it ought to display. It's opening the table and showing the first record by default.

Are you relying on the fact that the grid and the called form are both bound to the same table so that the form should open on the same record that you were on when you left the grid? If this is the case then you don't need to pass a parameter at all.

I'm not sure why you're passing the first name across as a parameter. If you were to pass the primary key across then you could do a SEEK() in the Init of the called form and move to the right record. This is the safest method because it makes the called form into a self-contained unit.

Geoff Franklin
 
Geoff I think you are correct. However both the grid and the form it calls are bound to the same table. And when I try to point to a record by highlighting it in the grid, I cant figure out how to make that record show up in the "contact" form.

I worked on the parameter deal and all it did was open the "contacts" form with the name in the field of the grid in record #1 replacing the name I had in record #1 previously. I just want to open a form up to edit a record. I havent even thought of how to open the form up to add a new record. I have every book on Vfp and can find no simple record navigation example to copy. Thanks for the help anyway I will continue to play with it.
 
kstart,

I hope you have it working now but thought I would try to help since I very recently was in the same position you seem to be in now.

As Geoff suggested, your data source for the grid would determine how you handle the transfer. The Data Session would also enter into the equation.

Would you comment on the data source for the grid and Data Session for the form? That was the source of so much of my confusion.

Judi
 
Judi,

I do not have it working ...Yet, but the record source for the grid, is the table "contacts" and the form has a data session of 3.

The data environment for the second form is the table "contatcs" also and it has a data session 3 also.
 
kstart,

Is the data session private or default? I was referring to the Data Session property of the form. I ask because if you are using the default for both then the is table available to both and you should be able to just locate the record in the grid and call the form.

If you are using private data sessions then you will have to make the table available to both forms either by using code to select the table or using the Data Environment of the form.

As Geoff told you above, if you pass an index key then you can SEEK() the key in the Init of the called form.

Since I use Private Data Sessions for all of my 'called' forms I would do this as follows.

On the 'called -frmEdit' I set Data Session = 2
In the DAta Environment of the form I add the table to use with index on the field that I will pass as the parameter.
I have both forms with the table available and indexed on same key, then
from the 'calling form - the grid' in the double-click event of the text box in the column holding the index field -
Code:
DO FORM frmEdit WITH This.Value

Then in the Init of the 'called form - the edit form' put -
(must be the very first thing there)
Code:
LPARAMETERS lcKeyValue
SEEK lcKeyValue

or you can store the lcKeyValue as you said above if you need it later.

Hope this makes some kind of sense since I am new to this.
I am just telling you what I worked out with a lot of help. I have gotten so much help from the great pros on this forum that I hope I can give some back. This is just my way and certainly not the only way.

Please let me know if what I have said helps and I hope others will be sure to correct any errors I have made.

Judi
 
Ok I kinda follow you Judi, both forms are set at private data sessions. Both share the same data environment table of "contact" where the primary key is "contactid" which is an autointeger field. SO I guess the Parameter issue is what I am having the issue with. The DO FORM myform with this.value is understood. But the init event is what I am missing. I dont think I need to make a new property for the form as I dont realy need it for anything later. and I am just missing the syntax of constructing the Lparameters statement. Thanks you are all so much help. I have been a policeman for 22 years and I would rather wrestle a guy with a gun right now......
 
kstart,
I know the feeling. I just got back into this recently. I programmed in fox many years ago. Retired recently from education. OOP is a different world from what I knew.

Anyway, you just need to put

LPARAMETERS some variable (doesn't matter what you call it)

example:
LPARAMETERS lcKeyValue &&this will catch the value you passed)
SEEK lcKeyValue

Do you have text fields on the called form to receive the data or some other way to view it?

This should do it. I can't imagine why not. Please let me know.

Judi
 
Judi,

Thanks for all the help first of all. I am so new that I am trying to take in so much info. I am learning a tremendous amount thanks to this forum.

I have all text fields on the called form. And I try everything but I get an error 9 Data type mismatch. is that because my index on the table is a autointeger? Should my variable be something like iKeyValue? And whats with the m. stuff?

Keith
 
Keith,

Do you know how to use the debugger to step through and see what is giving you the error? I see that you have VFP9 and I am still using VFP6 :-( so there may be some things that are different and I will not know. I hope others will jump in. I don't think that the autointeger should make a difference.

Is there a reason that you suspect the autointeger?

Are your text boxes tied to a controlsource?

And whats with the m. stuff?
The only way that I know m. is as in memory variables which I used to use with scatter and gather? Would you say more about the m. !

Judi
 

Kstart,

I see Geoff and Judi have put you in the right direction since I was last here.

You asked:
And whats with the m. stuff?

It's used to distinguish a variable from a field with the same name. For example, if you had a field called Address, and you wanted to create a variable called Address, you would prefix the variable name with m.

It some circumstances, using m. improves performance, but only very slightly, and in some cases it can make performance worse (I think Geoff has done some research on this). In VFP 9.0, it's more beneficial than in earlier vesions, performance-wise.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

My sites:
Visual FoxPro (www.ml-consult.demon.co.uk)
Crystal Reports (www.ml-crystal.com)
 
Judi,

I did not suspect the autointeger field to be the problem I just looked at your variable name of lcKeyValue wherein I believe
L=local, c=character, and KeyValue = the name

Since my index field is an integer I was wondering if liKeyValue would be correct instead, but it doesn't work either.
So I will keep trying to figure it out. Maybe a day or two tactical retreat will help me.
 
kstart,

You are right in what my variable letters stand for but that should not make any difference in your code working. The designations are just for readability.

Have you tried the debugger to see what is throwing the Data Type mismatch? Does data show in any of your textboxes?

Judi
 
KStart - After reading through this thread, I still feel confused about which form is called which and whether you're putting the LPARAMETERS statement in the right form.

Which form starts first? How is it called? What action on that form calls the other form and what does the calling code look like?

Tamar
 
Tamar,

I understand your confusion, however I am learning how to articulate the problem better thanks to all the pros in the forum. The calling form is the form named "change" it is a simple navigation form with a grid. It is called from a cmd button captioned "Find Record." The grid shows the contents of a table named "Contacts" it has a private data session-2. In the first column, text1 reflects the "Contacts" table's ID field, "contactid" which is an auto integer. In the dblclick event of text1 I have

DO FORM contactentry with This.value

(i have changed the original name from contacts to contactentry, confused myself...)

The form "contactentry" is the actual form that is called. It's purpose is to enter all the data pertaining to the contact person. On this form I made a new property named "keyvalue." So in the intit event of form contactentry I have:

LPARAMETERS linumber (based on local integer)
This.keyvalue=linumber

SO there you have it I expected to dblclick on the text1 in the grid on form "change" and see form "contactentry" open showing populated with the actual record I selected in the grid. Both forms share the same table as their data environment,and are both Private data sessions.

Alot of the modifications have been made as a result of all the help I have been getting here.
 
Okay, now I understand what you're doing. I see two alternatives.

First, if ContactEntry is only going to be called from Change, don't use a Private data session for it. Instead, set it to Default data session and it will share the Change form's data session. Then, you won't need to pass the parameter as the record pointer will be in the right place when you get there.

If that isn't an option for you, then you need some code in the Init to take the input value and move the record pointer to the specified record.

Tamar
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top