Results 1 to 6 of 6

Thread: subtrating 1 field from another in 2 seperate forms

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2006
    Posts
    6

    Angry subtrating 1 field from another in 2 seperate forms

    Ok....

    I have an item form with a field called Stock in it. This is the current stock of each particular item.

    In my Sale form I have added a subform of my item form as some had suggested this too me.

    I click add record choose the item that has been sold from a combo box, i then choose how many are sold and the date of when they were sold.

    Then i click save record to keep it. When i press this i want it to update the current stock by subtracting the quantity sold to get a new value.

    This is the code i currently have for my Save button

    VB Code:
    1. Private Sub save_Click()
    2. Dim stock As Integer
    3.  
    4. stock = stock - Quantity
    5. On Error GoTo Err_save_Click
    6.  
    7.  
    8. DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
    9.  
    10. Exit_save_Click:
    11. Exit Sub
    12.  
    13. Err_save_Click:
    14. MsgBox Err.Description
    15. Resume Exit_save_Click
    16.  
    17. End Sub

    But it doesn't work.

    I hope this explains my problem.









    Edit: Fixed [vbcode][/vbcode] tags. - Hack


    Andrew

  2. #2
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Re: subtrating 1 field from another in 2 seperate forms

    this should be in database development.... but try this..

    first:


    remove..
    Dim stock As Integer

    then.. note the Me.Stock...
    when you type me then "." a list should popup..
    is stock in the list? if so.. pick it... then do the same for
    quantity...
    this should work then
    VB Code:
    1. Private Sub save_Click()
    2.  
    3. On Error GoTo Err_save_Click
    4. me.stock = me.stock - me.Quantity
    5.  
    6. DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
    7.  
    8. Exit_save_Click:
    9. Exit Sub
    10.  
    11. Err_save_Click:
    12. MsgBox Err.Description
    13. Resume Exit_save_Click
    14.  
    15. End Sub
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  3. #3
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Re: subtrating 1 field from another in 2 seperate forms

    just had a thought.. if quantity or stock is on another form u need to specify the form name instead of me

    form_frmName.stock
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: subtrating 1 field from another in 2 seperate forms

    Access VBA question moved to Office Development

  5. #5

    Thread Starter
    New Member
    Join Date
    Jan 2006
    Posts
    6

    Re: subtrating 1 field from another in 2 seperate forms

    Thanks alot!

    Problem solved

    Andrew

  6. #6
    Member
    Join Date
    Jan 2005
    Posts
    44

    Re: subtrating 1 field from another in 2 seperate forms

    jolly good
    HALF LIFE 2 for president

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width