I managed to get the form populating with the 0, this is the code I'm using on the main form in the "onload" event.
Code:
Private Sub Form_Load()
Dim strBarsReturned As String
Dim OrderID As Long
Dim strSQL As String
strBarsReturned = 0
OrderID = Me!NightCountOrdersSubform.Form!OrderID
strSQL = "UPDATE Inventory set Inventory.[BarsReturned] = ('" & strBarsReturned & "') where Inventory.[OrderID] = OrderID;"
CurrentDb.Execute strSQL
Me.NightCountEnterReturnsSubform.Form.Requery
End Sub
I have my table open in the background before I open this form, once I open then form I can visually see that the field "BarsReturned" does get populated with 0 for all the records which also happens on the form so at first I was happy and thought all was good but here's my problem now.
As I mentioned I have a textbox on that form, in the same subform as "BarsReturned" which is called "BarsSold". There's another textbox on another subform called "BarsGiven". Now when someone enters a number in "BarsReturned" it subtracts it from "BarsGiven" and puts the answer in "BarsSold" which is bound to table "Inventory" (the order details)
So when the form is open and a user enters 0 in the "BarsReturned" textbox it says all was sold. This is what I wanted to happen using the code above.
It is putting the 0 in the textbox for all the records however its doing it differently then if a user was to do it. Its not triggering the math for "BarsSold".
The math for "BarsSold" is in the "AfterUpdate" event on the "BarsReturned" textbox.
So when this code runs the form isn't assuming an update for that textbox and triggering the code even though that textbox is being updated with the 0 it never had.
The idea is once this form opens the system automatically assumes everything given was sold and its up to the user to enter the correct returns.
Hope this makes sense and if you have any ideas that would be great.
Thanks