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

data environment problem 2

Status
Not open for further replies.

funghaifeng

Programmer
Dec 11, 2011
17
AU
hi there
i'm a newbie in VFP 9.0 programming and now i had a problem in my code..

i have 3 form in this project (not all, but this 3 is the problem)

form 1 called form 2, and form 2 called form 3..
form 2 and 3 doesn't use any data environment because i've read that if the base form had a table, the other form that called form that form will acknowledge the table too..
so i place all my tables in form 1 (because that form using all the table) and connect all the tables with relation
here is the problem :
when i called form 2 the data still appear, but when form 2 called form 3, data won't show up, even if its just use 1 table from form 1.
i've tried to give form 3 a table for itself, but it won't work..
is it because the relation so the data locked up in some position?or what?

thx for helping ^^
 
hi mike

thx 4 your answer

i've make sure that the data session in all forms are "1 - Default Data Session"

and when i open form 3, form 1 and form 2 are still open.

any suggestion?
 
Next question ....

Are you sure that the tables are not open in Form3? You say the tables "don't show up". What exactly are you seeing? How are you referencing the tables in Form3? And do you see an error message when you do so?

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
when i used the Data Session windows and run my program, i could see that all table in form 1 are still open when form 3 running.

what am i exactly i saw is just and empty grid and textbox, that grid is supposed to show all data in one table from form 1.

to referencing the table from form 1 i've used SELECT clause (ex : SELECT Table1) in form 3 init event. it worked once.

i dont see any error message here, that what's makes me very confused..
 
You're on the right track. Looking into the session window in paralell to the forms, you see which tables are open.
As you don't see data in the conrols of form3, check how the controls are set up.

Also check, if the relations you have set up filter records in a way, not leaving any related records to show.

For example if you relate two tables orders and orderitems and you position on an order with no orderitem, then the record pointer in orderitems will be at EOF (end of file) and nothing is shown.

Relations don't lock records, but they position in the related tables towards related records, or, well, to EOF, if no match is found.

Bye, Olaf.
 
If you can see the tables in the Data Session window when Form 3 is active, then that looks like the tables are correctly open. So it's likely that the cause of the problem is something to do with the controls on the form.

To verify that, let's focus first on the textbox. Does that textbox's ControlSource property point to a field in one of the open tables? If not, set the ControlSource now, and see if that makes a difference.

If that doesn't solve it, try this:

Add a temporary command button to the form. In its Click event, add this code:

Code:
SELECT Table1  && or whatever the table is called
GO TOP
Thisform.REFRESH

Run the form and click the button. Can you see any data now in the text box? If so, the tables must be open correctly, and the problem lies elsewhere.

Note that it's not enough to SELECT the table in the Init of the form. You really need to do it whenever you reference the table, given that you can't know if another table has become selected in the interim.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
to make this clear..i'll post the code here..^^
and u should know that this form, is supposed to be a search form

thisform.text1.interactivechange : (doesnt have control source)
------------------------------------------------------------------
IF !EMPTY(this.Value)
SET FILTER TO ALLTRIM(UPPER(thisform.txtnmobat.Value)) $UPPER(t_obat.nama_obat)
ELSE
SET FILTER TO
ENDIF
thisform.grdT_obat.Refresh()
------------------------------------------------------------------

thisform.init :
------------------------------------------------------------------
SELECT t_detail_periksa && this is for example orderitems table
LOCATE FOR EMPTY(quantity)
IF !FOUND()
INSERT INTO t_detail_periksa(no_periksa) VALUES (nomore)&& to make an empty record on parent so the search result can be inserted in that record
ENDIF

Thisform.grdT_obat.Column3.InputMask="999,999,999.-"
Thisform.grdT_obat.HighlightBackColor=RGB(0,0,255 )
Thisform.grdT_obat.HighlightForeColor=RGB(0,0,0 )
Thisform.grdT_obat.HighlightStyle = 1

SELECT t_obat && and this table is items table, this is the table that should be shown in the grid but it wont
------------------------------------------------------------------

thisform.grdT_obat.recordsourcetype = 1.Alias
thisform.grdT_obat.recordsource = T_Obat

thats all, there is also an "Add" button and exit but i think its not necessary to shown here, bcause its just insert an item to t_detail_periksa table
 
First, do what I suggested earlier with the textbox. A textbox is inherently simpler than a grid, so it's better to focus on that for the moment.

That said, I note that your grid does not appear to have a record source. Check that you have set its RecordSource property to the alias of the table. And its RecordSourceType to 1.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
mike..

i have already did what you suggested earlier, at the first run, the textbox was blank, and the color turns out to gray, but when i click the button i made, the data shown. but the grid still empty.. :(

actually i have set that property. check my last post and see below thisform.init code

and for you to know that at the first run, the grid seems to show the data, but just for a blink and then it's turn to an empty grid without i did anything to it?

anyway, thx for going this far to help me.. :)
it's really nice to know you mike.. :)
 
thisform.grdT_obat.recordsourcetype = 1.Alias
thisform.grdT_obat.recordsource = T_Obat

Do you do this in code?

Then change to:

thisform.grdT_obat.recordsourcetype = 1
thisform.grdT_obat.recordsource = "T_Obat"

Or completely skip this code and simply set the grid properties at design time.

One thing to you as a newbie: The Property Window shows string and numeric and boolean properties in the same way - as a text. But that means if you want to port what you see to code, you must be aware of the type of the property. Eg in the property window you can set recordsource to T_Obat without the string delimiter quotation marks. Foxpro knows this is meant as a string literal and not an expression or variable. If you set this in code, T_Obat would be interpreted as a variable name and you would get an error, if no variable T_Obat is defined at the moment you do thisform.grdT_obat.recordsource = T_Obat

Some poeple get into the habit of preceding all settings in the property window with =. That is in the proeprtywindow you can set recordsource ="T_Obat". This works, as foxpro will evaluate such property settings. This way the property windows looks the same as code you would need to write as a replacement for setting the properties manually during design time.

Bye, Olaf.
 
Olaf :

i didn't do that in code..i did that in property windows.. see that i write it below the ----------- mark

isee, i've already knew it but thanks anyway for your advice.. :)

Mike :

nope, thats not the problem..i've already moved the code in my textbox but the problem still there..
 
yup...

i've temporary removed the filtering code from my textbox and run my program once again, but nothing change.. :(

i've been thinking about this and what do you think about this thought:

when i choose one record in the orderitem table, the item table show only the record that relates to orderitem table, so when i open form 3, in init event i created an empty record that doesn't have any child in item table. so the grid turns to blank, CMIIW
 
hi danfreeman

thanks for your reply...
when i run the program without compiling it through run mode,
it is showing the image, but when build an exe, running this
exe does not show image on the report.

kindly help me.
kindly seen the attachment

the above is the output and the below is the input method of blob am using

rgds
 
mike..

is my problem a dead end?
is there no other way to solve this problem?

help me, i'm running out of time.. :(

pleasee..
 
Funghaifeng,

No, you're problem is not at a dead end. It's just that I have other things to do, and can't always give an instant reply, much as I'd like to (and the same goes for the other people here).

I don't have an immediate answer for your specific problem. However, I do wonder if you are making it more complicated than it needs to be.

Instead of the business of the empty record, I'd suggest a different approach. Something like this:

1. Create a form with a text box, a grid and a command button.

2. In the Click of the button, put code something like this:

Code:
IF NOT EMPTY(thisform.Text1.Value)
   thisform.Grid1.RecordSource = ""
  SELECT * FROM t_obat ;
  WHERE ALLTRIM(UPPER(nama_obat)) = ALLTRIM(UPPER(thisform.Text1.Value)) ;
  INTO CURSOR csrResults

  IF RECCOUNT("csrResults") = 0
    MESSAGEB0X("Not found")
  ELSE
    thisform.Grid1.RecordSource = "csrResults"
    thisform.Grid1.Refresh
    thisform.Grid1.SetFocus
  ENDIF
ENDIF

I'm not saying that the above is 100% correct. I just wrote it off the top of my head. But, the point is that it is the general approach that I think most of us would take in this situation.

With this solution, the user will enter the search term in the text box, then click the button. If any records are found, they will be displayed in the grid. If there are no records, the user will see a mesage and the grid will be empty.

Mike



__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top