Question : Add calculated column to subform data sheet

I have 3 tables Main, Details, Transactions.  I have a 3 forms Main, subform of Main (sfmDetails) and subform of sfmDetails called (sfmTran).

Users enter in part numbers and qtys in the detail subform.  The form gets its data from a select query.  After the part are entered the user goes to the Transaction subform.  Here they can log as parts are issued to the shop.  I have a combo box that looks up the parts just added in the above details subform for the user to choose.

What I need to do is have create a column in the Detail subform to show up in the datasheet view that is a running total of qyt on hand (Qty - Qty issued).

I have mades a totals query that gives me the total issued for each part.  I tried to use this query joined to my Detail select query and I got the On hand qty to work but  the resulting query would not let me add a new record.

It looks like from what I read here that joining a query to my select query made it so it would  not be able to add new records to the table.

Can I open the detail subform in design view - add a text box and have it show my on hand calculations from a query?  If so how would I do this?

Answer : Add calculated column to subform data sheet

Hi John

Yes, this is definitely an annoying "feature" of Access.  If a query includes a subquery that is not updateable, then that will render the entire query not updateable.

However, you can use a domain function, such as DSum or DLookup.

I'm a little hazy about yout table design and relationships, but as an example, you could have a textbox with a control source something like this:

=[InitialQty] - DSum( "Qty", "tblTran", "PartNumber='" & [PartNumber] & "'" )

Another method that might help is to have a hidden textbox (txtSumQty) in the header or footer of sfmTran to sum the individual transaction quantities:
   =Sum( [Qty] )

Then a textbox on sfmDetail can refer to this result:

   =[InitialQty] - [sfmTran].[Form].[txtSumQty]

Good luck!
--
Graham

Random Solutions  
 
programming4us programming4us