Hi,
I have 2 tables with a "one to many" relationship. I want to create my own form (not using wizard) for this two tables. The fields of the parent table are mostly textboxes of the form and for the child table I have a grid Object.
What I would expected is that whenever I move the record pointer in the parent table and reload the values in the textbox controls ( using scatter memvar and refresh() method of the form), the content of the grid Object will change with the related data. It is not working as I expected. I have the same content, sometimes nothing in the grid. What is wrong ?
The navigation buttons contain:
select 1 && master table
SKIP 1 && SKIP -1, GO TOP, test for EOF(), BOF() etc.
scatter memvar
&& refresh grid
&& refresh
The code is something like this (please ignore the names of the fields, table, objects, the style of programming, they are not important) and I put the part of the code that I thought it is important for my question (no exit button):
select 1
IF !USED('SALARIATI.DBF')
use SALARIATI.dbf in 1 EXCLUSIVE
ENDIF
select 2
IF !USED('INTRETINUTI.DBF')
use INTRETINUTI.dbf in 2 EXCLUSIVE
ENDIF
SELECT 1
SET ORDER TO TAG Cod OF c:\salarii\intretinuti.cdx IN Intretinuti
SET RELATION TO cod INTO Intretinuti ADDITIVE
SET SKIP TO Intretinuti
set order to tag cod
go top
SCATTER MEMVAR
frmMyForm = CREATEOBJECT('Form') && Create a Form
frmMyForm.Width=750
frmMyForm.Height=500
frmMyForm.Caption="SALARIATI"
frmMyForm.Closable = .F. && Disable the Control menu box
frmMyForm.BorderStyle=2
frmMyForm.AddObject('lblcCod','Label')
frmMyForm.AddObject('txtcCod','txtMyTxtBox1')
frmMyForm.AddObject('lblcNume','Label')
frmMyForm.AddObject('txtcNume','TextBox')
frmMyForm.AddObject('lblcPrenume','Label')
frmMyForm.AddObject('txtcPrenume','TextBox')
frmMyForm.AddObject('grdGrdIntretin','MyGrid')
frmMyForm.lblcCod.Visible=.T.
frmMyForm.lblcCod.Left=10
frmMyForm.lblcCod.Top=49
frmMyForm.lblcCod.FontBold=.T.
frmMyForm.lblcCod.BackStyle=0
frmMyForm.lblcCod.Caption="Matricol :"
frmMyForm.txtcCod.Visible=.T.
frmMyForm.txtcCod.Left=72
frmMyForm.txtcCod.Top=47
frmMyForm.txtcCod.Width=50
frmMyForm.txtcCod.MaxLength=5
frmMyForm.txtcCod.InputMask="99999"
frmMyForm.txtcCod.ControlSource="M.Cod"
frmMyForm.lblcNume.Visible=.T.
frmMyForm.lblcNume.Left=10
frmMyForm.lblcNume.Top=77
frmMyForm.lblcNume.FontBold=.T.
frmMyForm.lblcNume.BackStyle=0
frmMyForm.lblcNume.Caption="Nume :"
frmMyForm.txtcNume.Visible=.T.
frmMyForm.txtcNume.Left=72
frmMyForm.txtcNume.Top=75
frmMyForm.txtcNume.Width=200
frmMyForm.txtcNume.ControlSource="M.Nume"
frmMyForm.lblcPrenume.Visible=.T.
frmMyForm.lblcPrenume.Left=10
frmMyForm.lblcPrenume.Top=105
frmMyForm.lblcPrenume.FontBold=.T.
frmMyForm.lblcPrenume.BackStyle=0
frmMyForm.lblcPrenume.Caption="Prenume :"
frmMyForm.txtcPrenume.Visible=.T.
frmMyForm.txtcPrenume.Left=72
frmMyForm.txtcPrenume.Top=103
frmMyForm.txtcPrenume.Width=200
frmMyForm.txtcPrenume.ControlSource="M.Prenume"
frmMyForm.grdGrdIntretin.Visible=.T.
frmMyForm.grdGrdIntretin.Left=5
frmMyForm.grdGrdIntretin.Top=305
frmMyForm.grdGrdIntretin.Width=533
frmMyForm.grdGrdIntretin.Height=120
frmMyForm.grdGrdIntretin.ColumnCount=2
frmMyForm.grdGrdIntretin.RecordSourceType=2
frmMyForm.grdGrdIntretin.RecordSource="Intretinuti.dbf"
frmMyForm.grdGrdIntretin.Column1.ControlSource="Intretinuti.cnp"
frmMyForm.grdGrdIntretin.Column1.Width=100
frmMyForm.grdGrdIntretin.Column1.Header1.Caption="Cod NP"
frmMyForm.grdGrdIntretin.Column1.Header1.FontSize=8
frmMyForm.grdGrdIntretin.Column1.Header1.FontBold=.T.
frmMyForm.grdGrdIntretin.Column2.ControlSource="Intretinuti.nume"
frmMyForm.grdGrdIntretin.Column2.Header1.Caption="Nume"
frmMyForm.grdGrdIntretin.Column2.Header1.FontSize=8
frmMyForm.grdGrdIntretin.Column2.Header1.FontBold=.T.
frmMyForm.grdGrdIntretin.Column2.Width=120
frmMyForm.SHOW(1)
I have 2 tables with a "one to many" relationship. I want to create my own form (not using wizard) for this two tables. The fields of the parent table are mostly textboxes of the form and for the child table I have a grid Object.
What I would expected is that whenever I move the record pointer in the parent table and reload the values in the textbox controls ( using scatter memvar and refresh() method of the form), the content of the grid Object will change with the related data. It is not working as I expected. I have the same content, sometimes nothing in the grid. What is wrong ?
The navigation buttons contain:
select 1 && master table
SKIP 1 && SKIP -1, GO TOP, test for EOF(), BOF() etc.
scatter memvar
&& refresh grid
&& refresh
The code is something like this (please ignore the names of the fields, table, objects, the style of programming, they are not important) and I put the part of the code that I thought it is important for my question (no exit button):
select 1
IF !USED('SALARIATI.DBF')
use SALARIATI.dbf in 1 EXCLUSIVE
ENDIF
select 2
IF !USED('INTRETINUTI.DBF')
use INTRETINUTI.dbf in 2 EXCLUSIVE
ENDIF
SELECT 1
SET ORDER TO TAG Cod OF c:\salarii\intretinuti.cdx IN Intretinuti
SET RELATION TO cod INTO Intretinuti ADDITIVE
SET SKIP TO Intretinuti
set order to tag cod
go top
SCATTER MEMVAR
frmMyForm = CREATEOBJECT('Form') && Create a Form
frmMyForm.Width=750
frmMyForm.Height=500
frmMyForm.Caption="SALARIATI"
frmMyForm.Closable = .F. && Disable the Control menu box
frmMyForm.BorderStyle=2
frmMyForm.AddObject('lblcCod','Label')
frmMyForm.AddObject('txtcCod','txtMyTxtBox1')
frmMyForm.AddObject('lblcNume','Label')
frmMyForm.AddObject('txtcNume','TextBox')
frmMyForm.AddObject('lblcPrenume','Label')
frmMyForm.AddObject('txtcPrenume','TextBox')
frmMyForm.AddObject('grdGrdIntretin','MyGrid')
frmMyForm.lblcCod.Visible=.T.
frmMyForm.lblcCod.Left=10
frmMyForm.lblcCod.Top=49
frmMyForm.lblcCod.FontBold=.T.
frmMyForm.lblcCod.BackStyle=0
frmMyForm.lblcCod.Caption="Matricol :"
frmMyForm.txtcCod.Visible=.T.
frmMyForm.txtcCod.Left=72
frmMyForm.txtcCod.Top=47
frmMyForm.txtcCod.Width=50
frmMyForm.txtcCod.MaxLength=5
frmMyForm.txtcCod.InputMask="99999"
frmMyForm.txtcCod.ControlSource="M.Cod"
frmMyForm.lblcNume.Visible=.T.
frmMyForm.lblcNume.Left=10
frmMyForm.lblcNume.Top=77
frmMyForm.lblcNume.FontBold=.T.
frmMyForm.lblcNume.BackStyle=0
frmMyForm.lblcNume.Caption="Nume :"
frmMyForm.txtcNume.Visible=.T.
frmMyForm.txtcNume.Left=72
frmMyForm.txtcNume.Top=75
frmMyForm.txtcNume.Width=200
frmMyForm.txtcNume.ControlSource="M.Nume"
frmMyForm.lblcPrenume.Visible=.T.
frmMyForm.lblcPrenume.Left=10
frmMyForm.lblcPrenume.Top=105
frmMyForm.lblcPrenume.FontBold=.T.
frmMyForm.lblcPrenume.BackStyle=0
frmMyForm.lblcPrenume.Caption="Prenume :"
frmMyForm.txtcPrenume.Visible=.T.
frmMyForm.txtcPrenume.Left=72
frmMyForm.txtcPrenume.Top=103
frmMyForm.txtcPrenume.Width=200
frmMyForm.txtcPrenume.ControlSource="M.Prenume"
frmMyForm.grdGrdIntretin.Visible=.T.
frmMyForm.grdGrdIntretin.Left=5
frmMyForm.grdGrdIntretin.Top=305
frmMyForm.grdGrdIntretin.Width=533
frmMyForm.grdGrdIntretin.Height=120
frmMyForm.grdGrdIntretin.ColumnCount=2
frmMyForm.grdGrdIntretin.RecordSourceType=2
frmMyForm.grdGrdIntretin.RecordSource="Intretinuti.dbf"
frmMyForm.grdGrdIntretin.Column1.ControlSource="Intretinuti.cnp"
frmMyForm.grdGrdIntretin.Column1.Width=100
frmMyForm.grdGrdIntretin.Column1.Header1.Caption="Cod NP"
frmMyForm.grdGrdIntretin.Column1.Header1.FontSize=8
frmMyForm.grdGrdIntretin.Column1.Header1.FontBold=.T.
frmMyForm.grdGrdIntretin.Column2.ControlSource="Intretinuti.nume"
frmMyForm.grdGrdIntretin.Column2.Header1.Caption="Nume"
frmMyForm.grdGrdIntretin.Column2.Header1.FontSize=8
frmMyForm.grdGrdIntretin.Column2.Header1.FontBold=.T.
frmMyForm.grdGrdIntretin.Column2.Width=120
frmMyForm.SHOW(1)