Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Try to append data from another table

Status
Not open for further replies.

monoDeveloper

Programmer
Apr 16, 2013
16
0
0
Hi everybody

I run SQL query to add dat from another table based on form object data, it works when i save as separate query but failed when i run inside VBA script command :

Code:
[COLOR=#4E9A06]'Append data to Temporary table[/color] 
DoCmd = " INSERT INTO SupplyOrderDetails_Temp " & _
" ( Supp_Order_SN, ItemID, Sup_Ord_Item_ExDate, Ord_Old_QTY ) " & _
" from ( SELECT Supp_Order_SN, ItemID, Sup_Ord_Item_ExDate, Sup_Ord_QTY " & _
" FROM SupplyOrderDetails " & _
" WHERE (Supp_Order_SN= " & Int([cbo_Order_SN]) & "))"

This is Saved query code:
SQL:
INSERT INTO SupplyOrderDetails_Temp ( Supp_Order_SN, ItemID, Sup_Ord_Item_ExDate, Ord_Old_QTY )
SELECT Supp_Order_SN, ItemID, Sup_Ord_Item_ExDate, Sup_Ord_QTY
FROM SupplyOrderDetails
WHERE (Supp_Order_SN=Forms!frm_Update_Receive_Supply_Order!cbo_Order_SN);

I want to know the reason & solution please.

 
Please provide the error message or other symptoms. I expect it might be something about expecting parameters of similar. If so the issue is the reference to the control on the form which doesn't exist when running the VBA.

Duane
Hook'D on Access
MS Access MVP
 
Erro is:


Run-time error '438':
Object doesn't support this property or method
 
Another modification & it's error

Code:
[COLOR=#4E9A06]'Append data to Temporary table[/color]
DoCmd.RunSQL = " INSERT INTO SupplyOrderDetails_Temp " & _
" ( Supp_Order_SN, ItemID, Sup_Ord_Item_ExDate, Ord_Old_QTY ) " & _
" from ( SELECT Supp_Order_SN, ItemID, Sup_Ord_Item_ExDate, Sup_Ord_QTY " & _
" FROM SupplyOrderDetails " & _
" WHERE (Supp_Order_SN= " & [highlight #FCE94F][cbo_Order_SN][/highlight] & "))"

Error is: Compiler Erro ... Argument not optional & refer to [highlight #FCE94F][cbo_Order_SN][/highlight]
 
What about this ?
Code:
DoCmd.RunSQL "INSERT INTO SupplyOrderDetails_Temp (Supp_Order_SN,ItemID,Sup_Ord_Item_ExDate,Ord_Old_QTY)" _
 & " SELECT Supp_Order_SN,ItemID,Sup_Ord_Item_ExDate,Sup_Ord_QTY" _
 & " FROM SupplyOrderDetails WHERE Supp_Order_SN=" & Forms!frm_Update_Receive_Supply_Order!cbo_Order_SN

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top