is the value Initial weight always set prior to the form being opened. Or is there the possibility of this value being set after this textbox has value.
I often use a function that check values on the exit of a textbox or in your example the BeforeUpdate event.
There may be a simpler solution, but this may work.
ALSO as a general rule NEVER put spaces in column names.
Code:
'---Require ADODB reference.
Private Sub BeginningWeight_BeforeUpdate()
IF NOT CheckValue ([BeginningWeight], [FOAMID_For_The_Foam_Type]) then
msgbox "Invalid Beginning Weight"
Cancel=True ' caused the changes to not be saved
END IF
End Sub
Public Function CheckValue (byval v_dWeight as double, & _
Byval v_lFoamID as long) as Boolean
Dim sSql As String
Dim oRS As ADODB.Recordset
sSql = "SELECT Initial_Weight FROM FOAM WHERE FoamID = " & v_lFoamID
Set oRS = GetRS(sSql)
If v_dWeight <= oRS(0) then CheckValue = TRUE
End Function
Public Function GetRS(ByVal sSql As String, Optional v_sParameter As String) As ADODB.Recordset
Dim oconn As New ADODB.Connection
Set oconn = CurrentProject.Connection
Set GetRS = oconn.Execute(sSql)
End Function