I have coded it as on button click event as:
Code:
Private Sub save_Click()
On Error GoTo Err_cmdClose_Click
Me.Dirty = False
MsgBox "Exchange Value Saved", vbInformation
DoCmd.Close
Exit_cmdClose_Click:
Exit Sub
Err_cmdClose_Click:
If Err.Number = 3270 Then
MsgBox "Data Incompelete Not able to save Data", vbCritical
Else
If Err.Number = 2001 Then
MsgBox "Data Incompelete Not able to save Data", vbCritical
Else
MsgBox Err.Number
MsgBox Err.Description, vbInformation, "Close"
End If
End If
Resume Exit_cmdClose_Click
End Sub
And on form:
Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
If Len(Me.indianInr & vbNullString) = 0 Then
MsgBox "You need to fill INR Value", vbInformation
'Cancel = True
DoCmd.CancelEvent
Me.indianInr.SetFocus
End If
If Len(Me.usdDollar & vbNullString) = 0 Then
MsgBox "You need to fill USD Value", vbInformation
'Cancel = True
DoCmd.CancelEvent
Me.usdDollar.SetFocus
End If
If Len(Me.dateFrom & vbNullString) = 0 Then
MsgBox "You need to fill from Date", vbInformation
'Cancel = True
DoCmd.CancelEvent
Me.dateFrom.SetFocus
End If
If Len(Me.Dateto & vbNullString) = 0 Then
MsgBox "You need to fill to Date", vbInformation
'Cancel = True
DoCmd.CancelEvent
Me.Dateto.SetFocus
End If
Me!dateAdded = Date
End Sub
As i get error message, i have thrown the message at error handling, which i dont find it right, is there any otherway to accomplish, the user cannot close the form until all the information is correct or else roll back.