How to add the stock quantity but that erase the total stock quantity any help!

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • hannoudw
    New Member
    • Aug 2010
    • 115

    #1

    How to add the stock quantity but that erase the total stock quantity any help!

    hi i have a form that contain 2 text box (article and qty) and a next button .
    when i click on the button a new form will open in datasheet view, contain 5 text box ( size, quantity, reference, article, qty_to_add).
    i want when i change the qty_to_add to modify the stock quantity (quantity in the second form).
    so i wrote this :
    Code:
     Private Sub Add_AfterUpdate()
    Me.Qty.Value = Me.Qty.Value - Me.qty_to_Add.OldValue
    DoCmd.DoMenuItem acFormBar, acRecordsMenu, 5, , acMenuVer70
    Me.Qty.Value = Me.Qty.Value + Me.qty_to_Add.Value
    End Sub
    and it work fine but the problem is that sometime the quantity.value is null and when i modify the qty_to_add the stock quantity became null.
    Any help please...
  • beacon
    Contributor
    • Aug 2007
    • 579

    #2
    Hi hannoudw,

    Try adding an If...Then statement that checks to see if the quantity is null before you start your other calculations.

    Code:
    Private Sub Add_AfterUpdate()
        
        If Not IsNull(Me.Qty.Value) Then
            Me.Qty.Value = Me.Qty.Value - Me.qty_to_Add.OldValue
            DoCmd.DoMenuItem acFormBar, acRecordsMenu, 5, , acMenuVer70
            Me.Qty.Value = Me.Qty.Value + Me.qty_to_Add.Value
        Else
            'Display a message to the user to enter a quantity
            MsgBox "Please enter a value in the quantity field.", vbExclamation + VBOKOnly, "Null Quantity"
            'Put the cursor in the Qty field so the user can enter a value
            Me.Qty.SetFocus
        End If
    
    End Sub

    Comment

    • missinglinq
      Recognized Expert Specialist
      • Nov 2006
      • 3533

      #3
      You can use the Nz() function to change a Null to Zero.

      Me.Qty.Value = Nz(Me.Qty.Value , 0) + Me.qty_to_Add.V alue

      Welcome to Bytes!

      Linq ;0)>

      Comment

      • beacon
        Contributor
        • Aug 2007
        • 579

        #4
        Originally posted by missinglinq
        You can use the Nz() function to change a Null to Zero.

        Me.Qty.Value = Nz(Me.Qty.Value , 0) + Me.qty_to_Add.V alue

        Welcome to Bytes!

        Linq ;0)>
        Completely forgot about Nz() Linq. I was addressing it from the perspective that null values weren't acceptable, so thanks for having my back.

        Comment

        • hannoudw
          New Member
          • Aug 2010
          • 115

          #5
          Thanks @missinglinq
          that solved the problem
          now i'm trying to have a control over the total number that i added . therefore i added 2 text box on the header of the datasheet form. on of them have default value =[Forms]![Add Qty]![qtyTxt] (and that's the total quantity that i'm adding) and the other is equale of the sum of the qty_to_add (=sum[qty_to_add])
          and it's not working...
          olso i tried to add a button in the header and i wrote this code :
          Code:
          Private Sub Command22_Click()
          If Me.sum.Value <> Me.q.Value Then
          MsgBox ("check the adding numbers")
          End If
          End Sub
          and still not working ... any help please

          Comment

          Working...