A family of Microsoft relational database management systems designed for ease of use.
I said "report" and meant "form".
A textbox on the form.
I did ask repeatedly whether you really meant "report".
What do you want to do on this form? Do you want to prevent the user from entering a value that doesn't conform to your specified format, or do you want to actually change any non-conforming format they enter to Null (or an empty string)?
If you just want to prevent them from entering a non-conforming value, then a control-level validation rule would probably be the best way to do that; e.g.,
ValidationRule: Like "?#####"
ValidationText: That's not a valid value, please correct it.
Alternatively, you could use the control's BeforeUpdate event to accomplish the same thing, but it's wordier:
Private Sub YourTextBoxName_BeforeUpdate(Cancel As Integer)
If Not (Me.YourTextBoxName Like "?#####") Then
Cancel = True
MsgBox "That's not a valid value, please correct it."
End If
End Sub
If you want to physically change an improperly entered value back to Null, then you would have to use the AfterUpdate event instead, because you can't update a control in its own BeforeUpdate event:
Private Sub YourTextBoxName_AfterUpdate
If Not (Me.YourTextBoxName Like "?#####") Then
Me.YourTextBoxName = Null
End If
End Sub
If you want to change existing values that the user *didn't* enter or modify via the form, then there is no event of the control or the form that would naturally lend itself to that. For that you would want to run an update query, as I suggested before.