in this subform below, when I add a row it adds another row by itself! why is that please? below is the code for after update event for the combo box categories
Code: Select all
Private Sub cboProductCategories_AfterUpdate()
On Error GoTo ErrorHandler ' Start error handling
' Check if a category is selected in cboProductCategories
If Me.cboProductCategories = 0 Then
' Set RowSource to show all products
Me.ProductID.RowSource = "qrycboProducts_All"
Else
' Set RowSource to show products filtered by category
Me.ProductID.RowSource = "qrycboProducts"
End If
' Select the first item in the ProductID combo box
' If Me.ProductID.ListCount > 0 Then
Me.ProductID = Me.ProductID.Column(0, 0) ' Select the first item
' End If
' Call the AfterUpdate event for ProductID
Call ProductID_AfterUpdate
' Exit sub to avoid reaching the error handler if no error occurs
Exit Sub
ErrorHandler:
' Display a message box with the error number and description
MsgBox "Error " & Err.Number & ": " & Err.Description, vbCritical, "Error in cboProductCategories_AfterUpdate"
' Optionally, you can also log the error to a file or table if needed.
End Sub
and below is the code for the on current of the form
Code: Select all
Private Sub Form_Current()
On Error GoTo Err_Handler ' Start error handling
' Set the value of the unbound combobox
Me.cboProductCategories = Me.ProductCategoryID
' Requery products dropdown so it will have products for this category
Me.ProductID.Requery
' Validate the form and remove any error highlights
' ValidateForm_RemoveHighlights Me
' Cache the row, in case user changes the product
'If Not Me.NewRecord And Me.OrderDetailStatusID = enumOrderDetailStatus.odsAllocated Then
' m_RowCache.ProductID = Me.ProductID
' m_RowCache.Quantity = Me.Quantity
' End If
'
' Exit the subroutine before reaching the error handler if no error occurs
Exit Sub
Err_Handler:
' Display a message box with the error number and description
MsgBox "Error " & Err.Number & ": " & Err.Description, vbCritical, "Error in YourSubroutine"
' Optionally, you can add logging or additional error handling here, if needed
Resume Next ' Continue execution with the next line of code after handling the error
End Sub