Hi
I have a form called 'frmBin' which has a sub form called 'frmBin subform'.
Within the subform I have some VBA which looks up some values and updates the database when 'binType' control is updated.
Here is the VBA...
Code:
'Calculates the bin width based on product dimensions or bin type dimensions
Private Sub recalculateBinSize()
Dim requiredBinWidthByProduct As Long
Dim requiredBinWidthByBinType As Integer
Dim updateBinWidthMethod As String
Dim binID As Integer
Dim updateBinWidthByProduct As String
Dim updateBinWidthByBinType As String
requiredBinWidthByProduct = Nz([allocatedBinId].[Column](10), 0)
Debug.Print "requiredBinWidthByProduct " & requiredBinWidthByProduct
requiredBinWidthByBinType = Nz([allocatedBinId].[Column](6), 0)
Debug.Print "requiredBinWidthByBinType " & requiredBinWidthByBinType
updateBinWidthMethod = Nz([allocatedBinId].[Column](5), 0)
Debug.Print "updateBinWidthMethod " & updateBinWidthMethod
binID = Nz([allocatedBinId].[Column](4), 0)
Debug.Print "binID " & binID
updateBinWidthByProduct = "UPDATE tblBin SET [bin_width_mm] ='" & (requiredBinWidthByProduct) & "' WHERE [bin_id] = " & (binID)
updateBinWidthByBinType = "UPDATE tblBin SET [bin_width_mm] ='" & (requiredBinWidthByBinType) & "' WHERE [bin_id] = " & (binID)
If updateBinWidthMethod = -1 Then
CurrentDb.Execute updateBinWidthByProduct
ElseIf updateBinWidthMethod = 0 Then
CurrentDb.Execute updateBinWidthByBinType
End If
End Sub
Private Sub binType_AfterUpdate()
recalculateBinSize
End Sub
The VBA looks up it's values from the Row Source attached to 'allocatedBinId' control.
Everytime I update 'binType' the VBA runs but the values being pulled from the Row Source are not correct, I think it seems to pull the values from the original Row Source from when the page loads or the first location that's loaded, I tried different things to make the Row Source provide the correct information but I'm struggling to make it work correctly. I am able to identify this as I've added some debug lines and are viewing the numbers in the immediate window.
I've attached a sample database with my form.
PlannerBinForm.zip
I would be greatful for some assistance on this.