How to get SQL return value displayed on my form 's unbound textbox

smyeong

Registered User.
Local time
Tomorrow, 00:08
Joined
Mar 17, 2003
Messages
27
Hi, all. I was wondering how to finetune below code to allow to my inbound combox box named 'code' to show query 's return value on my main form's textbox ? I did it by using Code_afterUpdate event .

I got 1 main form called frm_itemRequestHead which is link up to subform called frm_ItemRequestDetail. The subform got inbound combox box called code.
The main form got an unbound textbox called txtbalance
The query i wrote is tested ok when run in SQL view.

Below is my attempt to do it but it doesn't work and end up with system error saying "Compile Error: Argument not optional":

Private Sub Code_AfterUpdate()
[Forms]![frm_itemRequestHead].[txtbalance] = DoCmd.RunSQL 'SELECT Nz(Sum([ILQTY]),0)AS Cbalance From tbl_itemledger WHERE (((tbl_itemledger.ildate) <= #" & Date & "#))GROUP BY tbl_itemledger.ILLITM HAVING (((tbl_itemledger.ILLITM)='" & [Forms]![frm_itemRequestHead]![frm_itemRequestDetail].[Form]!Code & "'));"
End Sub

Hope u guys can understand what i was trying to say ..Thanks and best Regards :)
 
Look up DSum in the Help.

You don't get a value back from DoCmd, it's not a function in the normal sense of the word "function" in VB context. But DSum is a function that can return the result of a SUM query.
 

Users who are viewing this thread

Back
Top Bottom