Ney André de Mello Zunino Guest
|
Posted: Sat Jun 03, 2006 8:43 pm Post subject: Related record in master table |
|
|
Hello.
In an application, I have a form which displays a master/detail
relationship on 2 DBGrids. The underlying data set for both grids are
TADOQuery objects. In order to synchronize the details grid with the
currently selected record on the master grid, I use the master's data
set's /AfterScroll/ event. The handler for that event first stores the
id of the currently selected master record (to be used when inserting
detail records), then used that id as a parameter to the details' query.
So far, so good. The problem comes when trying to add detail records.
Here is the scenario: I open the form and click on a master record with
no associated detail records. The first thing I noticed is that the
details grid shows an empty row, even though there are no records. I
suppose that's by design. Anyway, trying to enter information on that
row and posting it would cause the following error:
"You can not add or change a record because a related record is
required in table Master Table"
Ok, so it is telling me that I need to provide the "foreign key" field
(within quotes because, AFAICT, Access does not provide FK ref.
integrity control). Because I also noticed that, once I started editing
the columns on the grid, the details' datasource would change into the
/dsInsert/ state, I added code to its /OnStateChange/ event that would
put the ID of the selected master record into the "FK" field on the new
detail record. However, when I try to post that new record, I still get
the same error.
Would anybody be kind enough to help me understand this situation. I
could understand the initial error, but I don't know why it persists
even after I provide the id of the master record.
Thank you very much,
--
Ney André de Mello Zunino |
|