>I have a form on which i have a grid control ( for a one to many relationship). When I try and add a record to more than one line in the grid control(to the child) I am unable to. I first have to save the current record and then add again. How can I change this?
>
>Also, each time I try and add a new record, a screen pops up that ask if I want to add to the parent table, child table, or both. How do I get rid of this, so that it will automatically accept that I am going to add to both tables. I am using the standard record navigation buttons I found in the Component gallery.
>
>Thanx Stuart
Well, some points you need to handle:
-
Table Buffer Mode is 5, not 3 (Whole table buffer)-
Duplicate primary key problemTable Buffer:
Correct table buffer mode make it useful on grid data entry.
Because user may access the non-new record and want to save them all.
For Buffer 3, it cause problem (blank record) with save when change record(different row)
Duplicate Primary Key:
In general, you will set a Combine Field as Primary Key.
For example, ALLTRIM(Order_ID)+CHR(9)+ALLTRIM(ITEM) as a PK.
If user add 2nd record with same primary key, it will give 1884 error# and
force you take away that record.
My suggestion is better add record 1 by 1 with some key help to fast add next record:
If sudden program crash, most records are saved.
My current job is switch the CmdAdd button Caption to handle adding records:
Sample code below:
#DEFINE CAPADDITEM "\<Add OrdItems"
#DEFINE CAPFINITEM "Finish \<Add"
#DEFINE CAPUPDITEM "Update OrdItems"
#DEFINE CAPCANITEM "Canc\<el Add"
ThisForm.Lockscreen = .T.
IF THIS.CAPTION = CAPADDITEM
SELECT Orditems
APPEND BLANK
REPLACE Orditems.ORDER_ID with Orders.ORDER_ID
ThisForm.GrdOrditems.Column2.SetFocus
ELSE
IF TableUpdate(.T.) = .F.
Messagebox([Add Record fail], 16, [CapAddOrditems.Click error msg])
ENDIF
ENDIF
ThisForm.LOCKSCREEN = .F.
LPARAMETERS nKeyCode, nShiftCtrlAlt
#DEFINE CAPFINITEM "Finish \<Add"
DO CASE
CASE nKeyCode = 13
IF ThisForm.ActiveControl.Name = ThisForm.GrdOrditems.NAME
IF INLIST( ThisForm.GrdOrditems.ActiveColumn, 4, 5, 6, 7)
IF ThisForm.CmdAddOrditems.CAPTION = CAPFINITEM
Thisform.CmdAddOrditems.Click
Thisform.CmdAddOrditems.Click
ENDIF
ENDIF
ENDCASE
User will be add grid record with easy fill in some important data and
press {return} to fill in next record.
Hope above code gives you a general idea on handle add records.
The weak wait for chance, The strong bid for chance,
The clever notch up chance, but The merciful give you chance.