View Single Post
  #8  
Old April 21st, 2010, 09:01 PM posted to microsoft.public.access.queries
vanderghast
external usenet poster
 
Posts: 593
Default Append to two different tables

You insert trough the query, NOT trough one of the tables, since it is the
particular query which holds the gluing logic between the tables. If you
append trough a table, the query won't be considered at all, after all, and
that is not what we want.



Your actual query is probably NOT updateable (because it involves 3 tables,
with a cross join in addition to the inner join) :

---------------
FROM tblWorking,
Reservations INNER JOIN
ReservationDetails ON
Reservations.ReservationID = ReservationDetails.ReservationID;
---------------

Remove tblWorking, or insert it with its own inner join, but that is already
harder to make three tables working, so, let us start with only two tables.


In the user interface, open the query


--------------
SELECT Reservations.ReservationID, Reservations.FirstName,
Reservations.LastName, ReservationDetails.ReservationID,
ReservationDetails.RidersName
FROM tblWorking, Reservations INNER JOIN ReservationDetails ON
Reservations.ReservationID = ReservationDetails.ReservationID;
--------------

(I removed tblWorking and the computed expression, a computed expression is
not 'updateable')


***in data view***, and there, manually add a row in the grid, specifying
the fields which are NOT autonumbers (I assume those are ID) and leave the
foreign field null, that is, probably, add values to


Reservations.FirstName,
Reservations.LastName
ReservationDetails.RidersName



And save the record. The Reservations.ReservationID automatically generated
should be carried over to the new record in
ReservationDetails.ReservationID.

If the query is not updatable, if you cannot append a new row, in the grid,
maybe it is because the primary key of ReservationDetails is not included
(probably an autonumber for a field like
ReservationDetails.ReservationDetailsID ), or maybe a relationship between
the two tables is not right.


If your query is not updateable in the User Interface, it won't be
updateable under code. So, be sure you can manually add a row, in the grid,
for that query.

Once it works, manually, try appending using a recordset open on *that
query*, as example, which is somehow easier than using an UPDATE SQL
statement (while keeping the updateability).



Vanderghast, Access MVP