Reference field in query from form textbox

tstuve

New Member
Joined
Apr 29, 2002
Messages
19
Hi,

I've got a textbox on my main form (txtSubtotal) which I would like to show the subtotal for the current order being entered. There is a subform which allows the user to select items and quantities. I've got a field (subtotal) in a query that contains the correct data.

I put this code in the quantity_change event on the subform:

DLookup("SubTotal", "OrderSubtotal", "OrderSubtotal.OrderID = Parent!OrderID")

This works somewhat, but for some reason gives erroneous results (the value in the query is correct)

Can't I put an SQL statement in the ControlSource for this textbox? I've tried this, but keep getting the #Name? error. Here's the sql

select orderSubTotal.subtotal from ordersubtotal where ordersubtotal.orderid = Parent.OrderID;

Any help is appreciated.

Thanks
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
I don't think that you can use the SQL as a record source but you could use it in code and add the value that way.

Dim rst As DAO.Recordset
Set rst = CurrentDb().OpenRecordset("select orderSubTotal.subtotal from ordersubtotal where ordersubtotal.orderid = Parent.OrderID;")
Me.Parent("txtSubtotal") = rst.Fields(0)


HTH

Peter
 
Upvote 0

Forum statistics

Threads
1,221,645
Messages
6,161,044
Members
451,682
Latest member
ogoreo

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top