Hi, firstly please take a note on this code:
This code is behind a button on a pop-up form, allowing an user to add an item to an existing order. I have the following problem:
(1) After an item is added to an order (via append query), how do I refresh the form frmQuotesGenerator so that the item is automatically displayed on the frmQuotesGenerator's subform, [Order Details Extended]?
(2) Order details are being added via a pop-up box, however back to the main form's subform section (continuous form) there is also a product name field and price field. My problem is the price field hasn't been updated.
I have this code in place but I know this only applies if an user adds the item directly to the subform rather than via the pop-up form: DLookUp("UnitPrice","tblProducts","ProductID = " & [ProductID])
So how do I get around to these 2 problems? Sorry it's a bit long but thought I better explain everything first.
Many thanks in advance.
Joe
Code:
Private Sub AddItem_Click()
On Error GoTo Err_AddItem_Click
Dim UserConfirm As Integer
Dim strSQL As String
Dim OID As String
OID = Me.ChangeOrderNumber.Value
'Check if the relevant fields have been filled in
Dim strProductNameEntered As Variant
Dim strQuantityEntered As Variant
strProductNameEntered = Nz(Me.cboProductName.Value, "")
strQuantityEntered = Nz(Me.Quantity.Value, "")
If strProductNameEntered = "" Then
MsgBox "Please select a product from the drop-down box.", _
vbExclamation, "Product Required"
Exit Sub
ElseIf strQuantityEntered = "" Then
MsgBox "Please enter the number of items required in the quantity box.", _
vbExclamation, "Quantity Required"
Exit Sub
End If
'User confirmation required
UserConfirm = MsgBox("This item will be added to the quotation " _
& OID & " ." _
& vbCrLf & vbCrLf & "Press 'Yes' to proceed; 'No' to cancel.", vbYesNo, "Confirmation Required")
'Add product to existing OrderID
If UserConfirm = vbYes Then
strSQL = "INSERT INTO tblOrderDetails (OrderID,ProductID, Quantity) VALUES " & _
"(" & Me.OrderID & ", " & Me.ProductID & ", " & Me.Quantity & ");"
CurrentDb.Execute strSQL, dbFailOnError
Else
End If
DoCmd.Close acForm, frmSelectProduct
Forms!frmQuotesGenerator.SetFocus
DoCmd.DoMenuItem acFormBar, acRecordsMenu, 5, , acMenuVer70 'refresh QS
Forms!frmQuotesGenerator![Order Details Extended].UnitPrice = DLookup("UnitPrice", "tblProducts", "ProductID = " & [ProductID])
End_AddItem_Click:
Exit Sub
Err_AddItem_Click:
MsgBox "Error " & Err.Number & ": " & Err.Description & vbCrLf & _
" in " & Me.Name & ".AddItem_Click", _
vbOKOnly & vbCritical, "Error Occured"
Resume End_AddItem_Click
End Sub
This code is behind a button on a pop-up form, allowing an user to add an item to an existing order. I have the following problem:
(1) After an item is added to an order (via append query), how do I refresh the form frmQuotesGenerator so that the item is automatically displayed on the frmQuotesGenerator's subform, [Order Details Extended]?
(2) Order details are being added via a pop-up box, however back to the main form's subform section (continuous form) there is also a product name field and price field. My problem is the price field hasn't been updated.
I have this code in place but I know this only applies if an user adds the item directly to the subform rather than via the pop-up form: DLookUp("UnitPrice","tblProducts","ProductID = " & [ProductID])
So how do I get around to these 2 problems? Sorry it's a bit long but thought I better explain everything first.
Many thanks in advance.
Joe