I'm working on a database from another designer. This has a Customer form that summaries Orders in a subform. Highlighting an order and clicking an Orders button opens that order in a separate form that in a subform shows order items, or for new orders allows new ones to be entered. All this works fine and details of existing orders display correctly.
The problem arises with some new orders, initiated by running this code to add a new order for the current customer. OrderID in the Orders table isn't an AutoNumber so the code increments the last value used.
Code:
Public Sub AddRecord()
With Me.RecordsetClone
.AddNew
!CustomerID = Me![CustomerID]
!OrderDate = Date
!OrderID = DMax("OrderID", "Orders") + 1
.Update
.Bookmark = .LastModified
Me.Bookmark = .Bookmark
Me.SalesTaxRate = DLookup("[SalesTaxRate]", "My Company Information")
End With
End Sub
Sometimes this does not open a new blank record, but stays on the previous one even though I can see that !OrderID has incremented properly.