> Good Day VFP Experts,
>
> I have a problem in my mind how to connect the two tables or dbf files together just like one to many relationship and then connect those dbf files together in a form using a textbox and grid? When I save the record in the text box it will automatically saved and update in the grid which uses a different table or dbf? Any explanation or sample application that you can share with me? Thanks and More Power.
>
> Respectfully yours,
>
> Jake R. Pomperada :-D
Hi Jake! I am not so sure about what you are trying to ask here.
But try this example of mine. Copy and paste this into a prg then run.
Hope this gives you an idea. :-)
Set Safety Off
myForm = Createobject("FrmForm")
myForm.Show(1)
Define Class FrmForm As Form
Height = 500
Width = 750
AutoCenter = .T.
Add Object GrdRecords As Grid With;
AllowCellSelection = .F., ScrollBars = 2, Left = 50, Top = 200
Add Object GrdChild As Grid With;
AllowCellSelection = .F., ScrollBars = 2, Left = 400, Top = 200
Add Object TxtClientName As TextBox With;
Height = 25, Width = 200, Left = 125, Top = 100, Format = '!'
Add Object TxtAddress As TextBox With;
Height = 25, Width = 250, Left = 125, Top = 130, Format = '!'
Add Object LblName As Label With;
Autosize = .T., Left = 70, Caption = 'Name:', Top = 105
Add Object LblAddress As Label With;
Autosize = .T., Left = 70, Caption = 'Address:', Top = 135
Add Object CmdNew As CommandButton With;
Autosize = .T., Caption = 'New', Left = 450, Top = 50
Add Object Cmdsave As CommandButton With;
Autosize = .T., Caption = 'Save', Left = 500, Top = 50
Add Object CmdCombine As CommandButton With;
Autosize = .T., Caption = 'Combine', Left = 550, Top = 50
Procedure Load
Create Table Junk(Acctno i Autoinc Nextvalue 1 Step 1, CustName c(40))
Create Table ChildJunk(Acctno N(10,0), CustAddr c(60))
Endproc
Procedure Init
This.GrdRecords.RecordSource = 'Junk'
This.GrdChild.RecordSource = 'ChildJunk'
Endproc
Procedure ClearBoxes
This.TxtClientName.Value = ''
This.TxtAddress.Value = ''
Endproc
Procedure CmdNew.Click
This.Parent.ClearBoxes
This.Parent.TxtClientName.SetFocus
Endproc
Procedure Cmdsave.Click
Insert Into Junk(CustName) ;
Values(Alltrim(This.Parent.TxtClientName.Value))
Insert Into ChildJunk(Acctno, CustAddr) ;
Values(Junk.Acctno, Alltrim(Thisform.TxtAddress.Value))
This.Parent.ClearBoxes
This.Parent.GrdRecords.Refresh
This.Parent.GrdChild.Refresh
This.Parent.TxtClientName.SetFocus
Endproc
PROCEDURE CmdCombine.Click
SELECT Junk.AcctNo, Junk.CustName, ChildJunk.CustAddr ;
FROM junk;
INNER JOIN ChildJunk;
ON Junk.AcctNo = ChildJunk.AcctNo
Endproc
Enddefine
PS. Encode data and click save (as many as you want), the Name will be saved into the Junk Table (with autoinc field) while the Address will be saved into the ChildJunk Table. Click the Combine button to combine the entries of two tables into another table, in this case it is a cursor that holds the combined data of the two tables.
(coffee)