Connecting Tech Pros Worldwide Forums | Help | Site Map

Help! problem adding records to subform

Paul T. Rong
Guest
 
Posts: n/a
#1: Nov 13 '05
In form ¡°Order¡± there are 4 important controls:
- combo1 (unbounded, source from ProductID field of Product table),
- txt1 (I wish the product name will automatic show here after the user
inputs the product number in combo1),
- txt2 (where the user inputs the quantity of the Product needed, then press
¡°Enter¡± key, then triggers a Docmd.RunSQL ¡°insert into¡* code to add
records to the subform ¡°Order_detail¡±)
- a subform ¡°Order_detail¡±

here go the codes:

--------------------------------

Private Sub Form_Open(Cancel As Integer)

DoCmd.GoToRecord acDataForm, "Order", acNewRec

End Sub


Private Sub txt2_KeyDown(KeyCode As Integer, Shift As Integer)

If KeyCode = vbKeyReturn Then

If Me.combo1.Value <> "" And Me.txt2.Value <> "" Then

DoCmd.SetWarnings False

Me.Order_detail.Requery

Me.Order_detail.SetFocus

DoCmd.RunSQL "INSERT INTO tblOrderdetail ( OrderID,
ProductID, price, quantity )" _
& "SELECT [Forms]![Order]![OrderID] AS
Expression1, Product.ProductID, Product.price, [Forms]![Order]![txt2] AS" _
& "Expression2 FROM Product WHERE
(((Product.ProductID)=[Forms]![Order]![combo1])) ORDER BY
[Forms]![Order]![OrderID];"

DoCmd.SetWarnings True

Me.combo1.Value = ""

Me.combo1.SetFocus

Me.txt2.Value = "1"

End If

End If

End Sub


Private Sub CustomerID_AfterUpdate()
Me.Order_detail.SetFocus
End Sub

----------------------------------------------------------

where did I make mistake? Thank you for your patience, any help would be
very much appreciated.




Closed Thread