Inserting detail rows in master-detail configuration (VB4) 
Author Message
 Inserting detail rows in master-detail configuration (VB4)

I'm working on my first VB4 project, which involves a
simple master-detail relationship on one form.  I have
a data control and lots of bound edit controls for the
master table ('Orders'), and a data control and DBGrid for
the detail stuff ('DetailRows').  I've figured out how to
synch them by changing a SQL query when the 'Orders' data
control repositions.  Now I need to insert detail rows.

I would much rather that this worked by simply typing in
the bottom row of the grid rather than having extra 'add'
buttons.  To do this, I need to fill in two fields in the
new record 'in code'.

DetailRows      The detail table is keyed on two fields,
----------      'OrderNo' (which matches the primary key
OrderNo         for the parent Order record), and 'RowNo'
RowNo           (which just runs from 1 up).  These fields
Field3          should not be displayed.
Field4
Field5          When someone adds a new detail row (say, the
                fourth row in Order no 40743), I need to trap
this event and set the new record's OrderNo to 40743 and
RowNo to 4 before it is saved to the database.  I've tried
trapping BeforeInsert, but I get errors telling me I'm
trying to amend records without an Edit or Update command.

Can anyone suggest the best methods to trap and how to go
about this?

--
Andy Robinson



Sat, 15 Aug 1998 03:00:00 GMT  
 Inserting detail rows in master-detail configuration (VB4)

Quote:

> > DetailRows      The detail table is keyed on two fields,
> > ----------      'OrderNo' (which matches the primary key
> > OrderNo         for the parent Order record), and 'RowNo'
> > RowNo           (which just runs from 1 up).  These fields
> > Field3          should not be displayed.
> > Field4
> > Field5          When someone adds a new detail row (say, the
> >                 fourth row in Order no 40743), I need to trap
> > this event and set the new record's OrderNo to 40743 and
> > RowNo to 4 before it is saved to the database.  I've tried
> > trapping BeforeInsert, but I get errors telling me I'm
> > trying to amend records without an Edit or Update command.

Handle this in the data control Validate event.

If Save Then
   If IsNull(Data1.Recordset!OrderNum) Then
      Data1.Recordset!OrderNum = sThisOrderNumber
   End If
End If



Mon, 17 Aug 1998 03:00:00 GMT  
 Inserting detail rows in master-detail configuration (VB4)

Quote:

> I'm working on my first VB4 project, which involves a
> simple master-detail relationship on one form.  I have
> a data control and lots of bound edit controls for the
> master table ('Orders'), and a data control and DBGrid for
> the detail stuff ('DetailRows').  I've figured out how to
> synch them by changing a SQL query when the 'Orders' data
> control repositions.  Now I need to insert detail rows.

> I would much rather that this worked by simply typing in
> the bottom row of the grid rather than having extra 'add'
> buttons.  To do this, I need to fill in two fields in the
> new record 'in code'.

> DetailRows      The detail table is keyed on two fields,
> ----------      'OrderNo' (which matches the primary key
> OrderNo         for the parent Order record), and 'RowNo'
> RowNo           (which just runs from 1 up).  These fields
> Field3          should not be displayed.
> Field4
> Field5          When someone adds a new detail row (say, the
>                 fourth row in Order no 40743), I need to trap
> this event and set the new record's OrderNo to 40743 and
> RowNo to 4 before it is saved to the database.  I've tried
> trapping BeforeInsert, but I get errors telling me I'm
> trying to amend records without an Edit or Update command.

> Can anyone suggest the best methods to trap and how to go
> about this?

> --
> Andy RobinsonHi Andy-

  I had the same problem - tried in-table insert with DBGrid, then
pre-release of TrueDBgrid....guess what? I am using add buttons and SQL
Insert statement followed by refresh of detail table as ONLY reliable way
that works for now. I am sure when Data Widgets and Spread and final
release of True Grid appear this will be archaic work around code - but
it has the virtue right now of being the only code that works.
--
=================================================================
| Jacques Surveyer                    The Kelts                 |
| Imagenation - Consultant & Writer                             |
| 2360 Dundas St W. - Suite 1109      Like fallen gods          |
| Toronto, ON                                                   |

| (416)516-2075  or  (705)924-2251                              |
=================================================================


Tue, 18 Aug 1998 03:00:00 GMT  
 Inserting detail rows in master-detail configuration (VB4)

Quote:
>When someone adds a new detail row (say, the fourth row in
>Order no 40743), I need to trap
>this event and set the new record's OrderNo to 40743 and
>RowNo to 4 before it is saved to the database.  I've tried
>trapping BeforeInsert, but I get errors telling me I'm
>trying to amend records without an Edit or Update command.

>Can anyone suggest the best methods to trap and how to go
>about this?

The easiest way that I have found is to create a clone of the recordset
of the data control supplying the DBGrid. Then, position the bookmark
of the clone to that fo the LastModified of the data control in the
AfterInsert event.  Perform an Edit..Update sequence on the record of the
clone, and then refresh the data control supplying the grid:

Private Sub dbgItem_AfterInsert()
Dim rsclone As Recordset
Set rsclone = datItem.Recordset.Clone()
rsclone.Bookmark = datItem.Recordset.LastModified
rsclone.Edit
rsclone("ItemID") = txtItemID.Text
rsclone.Update
rsclone.Close  

End Sub

Try this and let me know how you get on

Clyde Davies



Wed, 19 Aug 1998 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Master-Detail with 2 seperate detail sections per master record, CR.NET

2. Link multiple datagrids to a single record (Master\Detail Form with multiple details)

3. Master-Detail Forms in VB4

4. Master-detail in VB4

5. Detail Info from first detail item in Group header

6. Details within details

7. Copy a master-detail record into another database?

8. Master/Details Problems

9. Master Detail - whats the difference?

10. sincronize Master Detail

11. HOWTO Create a master detail relationship datagrid for Web like Tree Structure

12. Q Master-Detail forms

 

 
Powered by phpBB® Forum Software