Automatically clear contents of a field

  • Thread starter Thread starter louonline
  • Start date Start date
L

louonline

Hello,
My thanks to all those who helped me with my project.
I'm now nearly finished and trying to put some cosmetic touches on it
to make it feel more "professional".
On my invoice form I have a textbox named "SALES_ID" with an field
length of 1.
The validation rule is set to "W" Or "P" Or "A" Or Is Null and the
validation text is "You must enter "W", "P" , "A" Or leave empty"
This works fine.

What I would like to see happen when the user enters an invalid
letter and the curser goes back to the "SALES_ID" textbox (after
clicking OK on the validation text message) is for the invalid letter
to be automatically deleted/cleared so the user just has to enter a
valid letter as opposed to having to backspace/delete the invalid
letter manually and then enter a correct one (or leave it blank).
As I said this is purely for cosmetic eloquence and I can live
without it but it would add a professional touch if it can be done.
I have tried a couple of things to accomplish the above but none of
them worked :(
I'll probably look a fool when you tell me that this is a standard
function in Access but as is said, `you'll never know if you don't
ask!'

Regards,
Lou
 
Instead of using a Validation Rule, use the BeforeUpdate event of the
control (or the form) to add a bit of code like (aircode):

Sub txtMyField_BeforeUpdate(Cancel As Integer)

Select Case Me.txtMyField

Case "W" Or "P" Or "A" Or Is Null
' Do Nothing
Case Else
MsgBox "You must enter 'W', 'P' , 'A' Or leave empty"
Me.txtMyField.Undo
Cancel = True

End Select

End Sub
--
Arvin Meyer, MCP, MVP
Microsoft Access
Free Access downloads
http://www.datastrat.com
http://www.mvps.org/access
 
Hi Arvin,
Just tried your suggestion.
It doesn't like the first case line.
I can get it to work if I alter it to this....

Case "W", "P", "A" 'Or Is Null

but I can't get it to accept the "Is Null" bit.

have you any suggestions?
I do need the option for it to be left null unless a valid code is
entered.

Regards,
Lou
 
Try:

Case "W", "P", "A", Null

or possibly just add another case for Null or Empty, that mirrors the first,
like:

Sub txtMyField_BeforeUpdate(Cancel As Integer)

Select Case Me.txtMyField

Case "W", "P", "A"
' Do Nothing
Case Null
' Do Nothing
Case Else
MsgBox "You must enter 'W', 'P' , 'A' Or leave empty"
Me.txtMyField.Undo
Cancel = True

End Select

End Sub
--
Arvin Meyer, MCP, MVP
Microsoft Access
Free Access downloads
http://www.datastrat.com
http://www.mvps.org/access
 
Back
Top