I've read numerous posts and I'm still not getting this. I have a form with 3 required fields: Supplier, name and PartNumber. I want the code to let the user be able to go back and fill in the field so I put the setfocus there - but instead the access message interupts and doesn't allow the correction. Then it states that can't save a record at this time (bla, bla). Could someone please look at what I have and assist me in making the form validation as well as allowing the user the chance to fix the mistakes:
Private Sub Form_BeforeUpdate(Cancel As Integer)
If IsNull(Name) or me.name =””Then
MsgBox "Required Name", vbCritical + vbOKOnly + vbDefaultButton1, "Missing Data"
Me![ Name].SetFocus
ElseIf IsNull(Part_Number) or Part_Number = “” then
MsgBox "Required P/N", vbCritical + vbOKOnly + vbDefaultButton1, "Missing Data"
Me![Part_Number].SetFocus
ElseIf IsNull(Supplier) or Supplier = “” then
MsgBox "Required Supplier", vbCritical + vbOKOnly + vbDefaultButton1, "Missing Data"
Me![Supplier].SetFocus
Else
Cancel = True
End if
End sub
Private Sub Form_BeforeUpdate(Cancel As Integer)
If IsNull(Name) or me.name =””Then
MsgBox "Required Name", vbCritical + vbOKOnly + vbDefaultButton1, "Missing Data"
Me![ Name].SetFocus
ElseIf IsNull(Part_Number) or Part_Number = “” then
MsgBox "Required P/N", vbCritical + vbOKOnly + vbDefaultButton1, "Missing Data"
Me![Part_Number].SetFocus
ElseIf IsNull(Supplier) or Supplier = “” then
MsgBox "Required Supplier", vbCritical + vbOKOnly + vbDefaultButton1, "Missing Data"
Me![Supplier].SetFocus
Else
Cancel = True
End if
End sub