Hi,
I have a frmOrders and sbfrmOrderDetails linked by OrderID. I want to limit the records on sbfrmOrderDetails based on a field TotUnits on the mainform. So, if the user enters 5 as the value in TotUnits, only 5 records are to be entered in the sbfrmOrderDetails.
This is the code I'm using:
This works. However, if i scroll on to enter a new Order on frmOrders, it won't let me add details on sbfrmOrderDetails. I know I'm supposed to set AllowAdditions = True but where?
Would there be a better way of doing this?
I have a frmOrders and sbfrmOrderDetails linked by OrderID. I want to limit the records on sbfrmOrderDetails based on a field TotUnits on the mainform. So, if the user enters 5 as the value in TotUnits, only 5 records are to be entered in the sbfrmOrderDetails.
This is the code I'm using:
Code:
Option Compare Database
Option Explicit
Dim var As Integer
Public Sub LimitRecords(var As Integer)
Dim conRecLimit As Integer
With Me.RecordsetClone
If .RecordCount > 0 Then .MoveLast
Me.AllowAdditions = (.RecordCount < var)
End With
End Sub
Private Sub Form_BeforeInsert(Cancel As Integer)
Me.[OrderLineNum] = Nz(DMax("OrderLineNum", "tblOrderDetails", "OrderID=" & Forms!frmOrders!OrderID.Value), 0) + 1
var = Forms!frmOrders!TotUnits.Value
LimitRecords (var)
End Sub
This works. However, if i scroll on to enter a new Order on frmOrders, it won't let me add details on sbfrmOrderDetails. I know I'm supposed to set AllowAdditions = True but where?
Would there be a better way of doing this?