Limit the data addition

emsadoon

Registered User.
Local time
Today, 14:53
Joined
Jun 6, 2013
Messages
83
I have a split design form, where user can select on any row and column of the spreadsheet view of the form and edit the data. Now, I want to write a code to limit the data addition(Row addition) to a certain number. But I still want to be able to edit the previous records added to the form.
I used Me.AllowAdditions = False, but when I want to select the previous records, it gives error:"You cannot go to specified record". Any thought how I can sort this out.
 
I just want to restrict the user from adding new records as soon as the number of records reach to a specific limit. Following is my code:

Code:
Private Sub Form_AfterUpdate()
   
    Dim dbs As DAO.Database

    
    Dim rstTest As DAO.Recordset
    
    Dim strQuery As String
    
  
    
    strQuery = "SELECT OrderingT.Order_ID, OrderingT.UnitsRequested, ([UnitsRequested])-Count([Product_ID]) AS [The Remaining Units] " + _
    "FROM (OrderingT INNER JOIN PackingSlipT ON OrderingT.Order_ID = PackingSlipT.Order_ID) INNER JOIN ProductT ON PackingSlipT.PackingSlip_ID = ProductT.PackingSlip_ID " + _
    "WHERE (PackingSlipT.PackingSlip_ID = " & Form.Tag & ") " + _
    "GROUP BY OrderingT.Order_ID, OrderingT.UnitsRequested;"
    
    Dim db As Database
    Set db = CurrentDb
    
    Set rstTest = db.OpenRecordset(strQuery)
    Me.Refresh
    If Not rstTest.EOF Then
        MsgBox "Order: " & rstTest!Order_ID & " has " & rstTest![The Remaining Units] & " units left"
        
    End If
              
          
    If rstTest![The Remaining Units] = 0 Then
    
         MsgBox "You cannot add more product"
         Me.AllowAdditions = False
         Me.AllowEdits = True
        
         
    End If
    
         
    
End Sub
 

Users who are viewing this thread

Back
Top Bottom