Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Do not allow Save or New Record unless condition is met.

Status
Not open for further replies.

Tmat

Technical User
Jul 22, 2000
27
US
I enter a check amount into the main form cutCheckAmount and in a sub form I am allocating the check to the corresponding departments. On the subform I added a txbxSum I need the txbxCheckAmount to equal txbxSum before it will allow me to precede either with closing the form or entering in a new record or give me a message Allocation does not equal check amount. I have been working with different versions of this but I can not get anything to work. Any help would be appreciated.
tmat

Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim cutCheckAmount As Integer
Dim txbxSum As Integer

If cutCheckAmount < txbxSum Then
MsgBox &quot;Error! Allocation greater then Check
Amount. You will not be able to save this record
or proceed.&quot;, vbExclamation + vbOKOnly
cutAmount.SetFocus
ElseIf cutCheckAmount > txbxSum Then
MsgBox &quot;Error! Allocation is less then Check
Amount.You will not be able to save this record or
proceed.&quot;, vbExclamation + vbOKOnly
txbxAmount.SetFocus
ElseIf cutCheckAmount = txbxSum Then
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
End If
End Sub
 
Which part of it is it that is not working, i.e. what is not working? Is it adding the record anyway, or not displaying the right message, etc? Let us know and we may be able to help. Have fun! :eek:)

Alex Middleton
 
I did try cancel but not after each msgbox.I will try that.
As for not working it allows me to enter in any amount in the allocation subform and doesnt do any thing. I can just go to a new record in the main form it doesnt seem to run the code not even a error debug?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top