I have a pop-up form in which user-defined parameters are entered. The
parameters are entered into a subform datasheet which is bound to a table.
I need to check the product of two parameters to make sure they are valid
before updating them (or closing the popup form), so I use this code:
Private Function BadValue() As Boolean
If Me!Die * Me!Site > 32000 Or Me!Die * Me!Site < 0 Then
MsgBox "Die and/or Site out of range." & vbCrLf & vbCrLf & _
"The product of Die and Site must be" & vbCrLf & _
"between 0 and 32,000 for any given Job File.", vbCritical, _
" Invalid Die or Site Value"
BadValue = True
Else
BadValue = False
End If
End Sub
Private Sub Die_BeforeUpdate(Cancel As Integer)
If BadValue Then DoCmd.CancelEvent
End Sub
Private Sub Site_BeforeUpdate(Cancel As Integer)
If BadValue Then DoCmd.CancelEvent
End Sub
The DoCmd.CancelEvent seems to work - the value is not updated if BadValue
returns True.
But the problem is users generally enter a value and then immediately click
the close cross in the upper right corner of the popup form. This results
in an error message:
"You can't save this record at this time."
Is there any way to avoid this error? I really don't want to create my own
"Close" command button, if I can avoid it. I would rather continue to use
the standard close box to let users close the popup form. Can the form be
prevented from trying to close if BadValue returns True?
Thanks in advance.