sd110404 . . . . .
Your so close, yet so far away . . .
[blue]
BobStubbs[/blue] suggestion of the BeforeUpdate Event is on target! Now I've never had the occasion to use the [blue]DoCmd.CancelEvent[/blue] because [purple]
every event that can be cancelled has its own Cancel Arguement![/purple]. Why the [blue]DoCmd.CancelEvent[/blue] doesn't work I can't tell ya, but I can tell ya [blue]with authority and great abundance of use[/blue], the [purple]
Cancel Arguement[/purple] does!
TheAceMan said:
[blue]When the [purple]Cancel Arguement[/purple] is set to true (Cancel = True), the BeforeUpdate event [purple]rolls back saving[/purple] and you stay in the edited field. With proper validating code, you can bet [purple]you'll go no where else until its proper![/purple][/blue]
Bear in mind from the time you start using the BeforeUpdate, you prevent future blank fields.
Now realize if you have enough old [blue]
saved[/blue] records, another method is required since events won't be triggered for these. For many of us this is called [blue]
Clean-Up[/blue], which usually involves [blue]use of a query[/blue] or a form based on that query, which returns [blue]only those records having those specific blank fields[/blue]. Example of a query to return empty fields:
Code:
[blue] SELECT PrimaryKeyName, RequiredFieldName
FROM YourTableName
WHERE (RequiredFieldName1 Is Null);[/blue]
Again at the very least you should [purple]
permanently prevent future errors[/purple] by having some code in the forms [purple]
BeforeUpdate[/purple] event:
Code:
[blue]Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim Msg As String, Style As Integer
Dim Title As String, DL As String
DL = vbNewLine & vbNewLine
If Trim(Me![purple][b]Text1[/b][/purple] & "") = "" Then
Msg = "No data in Comment field!" & DL & _
"Comments are not allowed to be empty!" & DL & _
"You must enter data in the comment field!" & DL & _
"The Database will not let you continue otherwise . . ."
Style = vbCritical + vbOKOnly
Title = "No Comment Error! . . ."
MsgBox Msg, Style, Title
[purple][b]Cancel = True[/b][/purple] [green]'Roll back saving![/green]
End If
End Sub[/blue]
[purple]Don't forget you cleanup![/purple]
See Ya! . . . . . .