PDA

Click to See Complete Forum and Search --> : subtrating 1 field from another in 2 seperate forms


davids26
Jan 10th, 2006, 12:59 PM
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


Private Sub save_Click()
Dim stock As Integer

stock = stock - Quantity
On Error GoTo Err_save_Click


DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70

Exit_save_Click:
Exit Sub

Err_save_Click:
MsgBox Err.Description
Resume Exit_save_Click

End Sub


But it doesn't work.

I hope this explains my problem.









Edit: Fixed tags. - Hack


Andrew

Static
Jan 10th, 2006, 01:12 PM
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

Private Sub save_Click()

On Error GoTo Err_save_Click
me.stock = me.stock - me.Quantity

DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70

Exit_save_Click:
Exit Sub

Err_save_Click:
MsgBox Err.Description
Resume Exit_save_Click

End Sub

Static
Jan 10th, 2006, 01:14 PM
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

Hack
Jan 10th, 2006, 01:25 PM
Access VBA question moved to Office Development

davids26
Jan 10th, 2006, 02:41 PM
Thanks alot!

Problem solved

Andrew

aatwo
Jan 10th, 2006, 02:41 PM
jolly good