DS wrote:
Hi, I have an order entry form with a subform attached for order
details. Whenever you add a product to the Order Details subform and
then you try to add the same product again in won't let you. Which is
fine. The problem I'm having is that I'll be using a scanner to enter
products and when you have two products in a row I need the subform to
make the quantity 2 not give me an error message that I already have the
product entered. I tried a work around by allowing duplicates, which
also works fine but now I have a product listed 2 or more times which
looks sloppy. Any solutions? If I write a Macro what would it say? If
I write code what would it say? Thanks Everyone,
DS
bo******@optonline.net
Since you have "saved" the record for the order, and you are scanning,
you might want to do a search for the id supplied by the scanner for the
record.
I don't know if you could do this with a macro. Maybe. Macros aren't
my strong suit. Here's some sample code. MF = MainForm. SF = SubForm.
ID = ScannedID of the item scanned, OrderID = ID of order from MF..
In the BeforeUpdate event of the scan, enter something like
Sub BeforeUpdate_ID(....)
Dim blnCancel As Boolean
Dim rst As Recordset
Set rst = Forms!MF!SF.Form.Recordsetclone
rst.FindFirst "OrderID = " & Forms!MF!OrderID & " And " & _
"ItemID = " & Me.ScannedID
If not rst.NoMatch Then
rst.Edit
'add 1 to the qty. You can figure out the qty to add
'you could use an InputBox to get the qty.
rst!ItemQty = rst!ItemQty + 1
rst.Update
'no need to add record
blnCancel = True
Endif
set rst = Nothing
Cancel = blnCancel
'if you want to display a message
msgbox "This item already exists and the qty has been incremented by 1"
Endif
I suppose you could do something like this instead...needs to be tested.
If not rst.NoMatch Then
'clear out current record
Forms!MF!SF.Form.Undo
'move to the record
Forms!MF!SF!Form.Bookmark = rst.Bookmark
Endif
With some playing around you should be able to get it.