Cancel=True problems!

R

riccifs

Hi to everyone,
on the KeyDown Event of my form I have that:

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyTab Then
Screen.ActiveControl.Text =
mixed_case(Screen.ActiveControl.Text)
End If
End Sub

And on the BeforeUpdate Event I insert that:

Private Sub txtPhone_BeforeUpdate(Cancel As Integer)
If Not rgxValidate(Me.ActiveControl.Text, "\(\d{3}\) \d{3}-\d{4}")
Then
MsgBox "I don't like " & Me.ActiveControl.Text & "."
Cancel = True
End If
End Sub

I got both mixed_case and rgxValidate to this web-site http://www.mvps.org/access/.
The problems is:
when I rich the txtPhone and hit the tab, after validated the message
box, the code stops itself.
I'm not very good to VBA coding but I think the problem is the
Cancel=True that stops the KeyDown event
How can I modify all that to make it works together? I need both
rgxValidate and mixed_case functions.
I will really appreciate everyone who would help me!

Bye,
Stefano.
 
L

Linq Adams via AccessMonster.com

So, to begin with, you want to format the data in every text box on your form
as if it were a person's proper name? That's what you're doing with the first
piece of code, and this seems a bit odd, to say the least. SHouldn't this be
reserved for the appropriate text box(es) rather than for every text box?

As to the second bit of code; if you see the validation failure messagebox
(which is what it is, it means that validation has failed) the code is
"stopping" because it is waiting for you to re-enter the phone number
correctly. It will stay at this text box until this correction is made. And
yes, you're correct in that the Cancel = True is the cause for this behaviour.
It forces the user to correct the data. Having validation rules make no sense
unless you're going to force the user to correct their mistakes.
 
R

riccifs

So, to begin with, you want to format the data in every text box on your form
as if it were a person's proper name? That's what you're doing with the first
piece of code, and this seems a bit odd, to say the least. SHouldn't this be
reserved for the appropriate text box(es) rather than for every text box?

As to the second bit of code; if you see the validation failure messagebox
(which is what it is, it means that validation has failed) the code is
"stopping" because it is waiting for you to re-enter the phone number
correctly. It will stay at this text box until this correction is made. And
yes, you're correct in that the Cancel = True is the cause for this behaviour.
It forces the user to correct the data. Having validation rules make no sense
unless you're going to force the user to correct their mistakes.

--
There's ALWAYS more than one way to skin a cat!

Answers/posts based on Access 2000

Message posted viahttp://www.accessmonster.com

Hi,
in other word the only thing I can do is to use the proper case
function for the appropriate text box(es) rather than for every text
box.
Is there no way to change the second sub so that both of them can work
together?

Bye,
Stefano

P.S.
I'm still not understanding how can I solve the problems!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top