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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Mandatory Field - Cant save record

Status
Not open for further replies.

dwichmann

IS-IT--Management
Jul 15, 2005
42
GB
I am trying to set up some mandatory fields for my form. I have placed the following code in the beforeupdate event

Private Sub Form_BeforeUpdate(Cancel As Integer)
If Delivery_Cost > 0 Then
GoTo end1:
Else:
MsgBox ("Please enter a delivery cost")
Cancel = True
end1:
End If
End Sub

this is working, checks if the delivery_cost field has a value and gives the user a message if it doesn't. After the message though it then gives the user a standard "Microsoft Access cannot save this record at this time" message. Is there anyway i can disable this.

Ideally i would like users to be prompted is they dont enter a value and the delivery_cost field to retain its focus.

Any help appreciated, sorry for waffling
 
It is not usually a good idea to use GoTo:
Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
If Nz(Delivery_Cost,0) = 0 Then
   MsgBox ("Please enter a delivery cost")
   Cancel = True
End If
End Sub

The reason you are getting the message is that Access is trying to save the record. You may wish to prevent this if all required information has not been entered. Here is a FAQ:
 
thanks for the help. just what i was after
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top