I have a form on my database that I use for invoicing.
It has a [ProductCode] combobox where I type in my product codes and when the correct one is selected, it populates the other fields (e.g. Product Description, Price etc.) If I want to add a new product, I type directly into the [ProductCode] combobox and if the item doesn't exist, it triggers the following NotInList event:
The "Products" form is a separate form which has further details, such as Unit Price, Supplier, Stock Levels etc.
However, it opens up "Products" as a blank record with (New) in the ID box, I end up having to type the ProductCode in again. I'd like to create the new record automatically, putting [ProductCode] from the previous form into [ProductCode] on the new form.
What do I need to add to the VBCode?
It has a [ProductCode] combobox where I type in my product codes and when the correct one is selected, it populates the other fields (e.g. Product Description, Price etc.) If I want to add a new product, I type directly into the [ProductCode] combobox and if the item doesn't exist, it triggers the following NotInList event:
Code:
Private Sub ProductCode_NotInList(NewData As String, Response As Integer)
'Suppress the default error message.
Response = acDataErrContinue
' Prompt user to verify they wish to add new value.
If MsgBox("Would you like to add this product to the database?", _
vbOKCancel) = vbOK Then
' open form to populate the various fields and carry up a new piece of the record
DoCmd.OpenForm "Products", , , , acFormAdd, acDialog, NewData
Response = acDataErrAdded
Else
' If user chooses Cancel, suppress error message
' and undo changes.
Response = acDataErrContinue
End If
End Sub
However, it opens up "Products" as a blank record with (New) in the ID box, I end up having to type the ProductCode in again. I'd like to create the new record automatically, putting [ProductCode] from the previous form into [ProductCode] on the new form.
What do I need to add to the VBCode?