|
Question : Auto-updating a view-based subform
|
|
Hi,
I have a form and subform. The main form is a typical "order form", and the subform shows the contents of the order. The datasource for the subform is a View rather than a single table, since I need to display data from more than one table. The SQL statement that generates the View is:
SELECT [ORDER].OrderID, [ORDER-DETAIL].EbayNum, AUCTION.Winner, LOT.LotNum, LOT.Description, LOT.WarehouseLoc FROM dbo.AUCTION INNER JOIN dbo.[ORDER-DETAIL] ON dbo.AUCTION.EbayNum = dbo.[ORDER-DETAIL].EbayNum INNER JOIN dbo.[ORDER] ON dbo.[ORDER-DETAIL].OrderID = dbo.[ORDER].OrderID INNER JOIN dbo.LOT ON dbo.AUCTION.LotNum = dbo.LOT.LotNum
In the subform, users see the auction items that are associated with the order that is being viewed in the main form. I would like for users to be able to add auctions to an order by entering an EbayNum directly into the subform datasheet, and having the remaining data (LotNum, Description, Location) fill in automatically. I also expect that, when this happens, a new record is being created in the ORDER-DETAIL table (tblORDER-DETAIL, OrderID, EbayNum) using the EbayNum supplied by the user and the OrderID of the current order on the main form. Can these two things be done when the datasource for the subform is a View rather than a single table?
Note: The View was created in SQL, not in Access.
Thanks in advance! Looking forward to a quick solution, since I'm at a standstill on my project...
|
|
Answer : Auto-updating a view-based subform
|
|
I have to apologize a bit as I let slip the fact that this is ADP with a SQL backend rather then JET. Without using JET, the behavior your seeing is correct (row fixes up after you move off of it) and a refresh is not going to do it because SQL won't do it until the record is committed.
If you want to see those fields before moving off the row (and the record getting committed), you'll need to populate those fields yourself.
You can do that from the AfterUpdate event of the EbayNum a couple of different ways (options are from simplest/poorest performance to more difficult/best performance):
1. Use DLookup:
Me.LotNum = DLookup("LotNum","dbo.AUCTION","EbayNum = '" & Me.EbayNum & "'") Me.Description = DLookup("Description","dbo.AUCTION","EbayNum = '" & Me.EbayNum & "'")
really simple to do, but your opening a recordset for each look up. Use for only 2 or 3 fields worth. More then that use one of the other methods.
2. Make EbayNum a combo and include the fields in the combo's underlying query, but hide them from view by settings the widths to 0. You can then use the combo's column property to read the columns and push the data into the controls.
ColumnCount 3 ColumnWidths: .5 in; 0 in; 0 in;
Me.LotNum = Me.EbayNum.column(1) Me.Description = Me.EbayNum.column(2)
Better as your not making repeated trips to the backend, but you're loading everything into memory when the combo loads. Not a good idea with large recordsets.
3. Open a recordset on dbl.Aution that returns a single record with the information and push the data into the controls from there.
Best method, but takes slightly longer to code.
With any of the 3 options, you will of course want to remove dbo.AUCTION from your base view for the subform.
Jim.
|
|
|
|