What am I doing wrong? 
Author Message
 What am I doing wrong?

Private Sub Code_BeforeUpdate(Cancel As Integer)
If Me.Code.Text Like "[A-Z]" _
Or Me.Code.Text Like "[A-Z]#" Then
Else
MsgBox "Enter a letter or a letter followed by a #."
Cancel = True
End If
End Sub

When the Else fires I get a second message saying validation rules violated.
Why?
This Field is Index.

Help says: "For forms, you can use the BeforeUpdate event to cancel updating
of a record before moving to another record."   BEFORE??

tx,
Paul



Sun, 22 Aug 2004 02:20:40 GMT  
 What am I doing wrong?
Does the text box or the table field also have validation rules?
Art


Quote:
> Private Sub Code_BeforeUpdate(Cancel As Integer)
> If Me.Code.Text Like "[A-Z]" _
> Or Me.Code.Text Like "[A-Z]#" Then
> Else
> MsgBox "Enter a letter or a letter followed by a #."
> Cancel = True
> End If
> End Sub

> When the Else fires I get a second message saying validation rules
violated.
> Why?
> This Field is Index.

> Help says: "For forms, you can use the BeforeUpdate event to cancel
updating
> of a record before moving to another record."   BEFORE??

> tx,
> Paul



Sun, 22 Aug 2004 04:33:02 GMT  
 What am I doing wrong?

Quote:

>Private Sub Code_BeforeUpdate(Cancel As Integer)
>If Me.Code.Text Like "[A-Z]" _
>Or Me.Code.Text Like "[A-Z]#" Then
>Else
>MsgBox "Enter a letter or a letter followed by a #."
>Cancel = True
>End If
>End Sub

Note that # is a wildcard, matching any numeric digit. If you want a
letter followed by # you must use

LIKE "[A-Z][#]"

Quote:
>When the Else fires I get a second message saying validation rules violated.
>Why?
>This Field is Index.

>Help says: "For forms, you can use the BeforeUpdate event to cancel updating
>of a record before moving to another record."   BEFORE??

Just add a line Me.Code.Undo to erase the user's input as part of the
Else.

                  John W. Vinson[MVP]    
    Come for live chats every Tuesday and Thursday
http://go.compuserve.com/msdevapps?loc=us&access=public



Sun, 22 Aug 2004 04:50:20 GMT  
 What am I doing wrong?
No.


Quote:
> Does the text box or the table field also have validation rules?
> Art



> > Private Sub Code_BeforeUpdate(Cancel As Integer)
> > If Me.Code.Text Like "[A-Z]" _
> > Or Me.Code.Text Like "[A-Z]#" Then
> > Else
> > MsgBox "Enter a letter or a letter followed by a #."
> > Cancel = True
> > End If
> > End Sub

> > When the Else fires I get a second message saying validation rules
> violated.
> > Why?
> > This Field is Index.

> > Help says: "For forms, you can use the BeforeUpdate event to cancel
> updating
> > of a record before moving to another record."   BEFORE??

> > tx,
> > Paul



Sun, 22 Aug 2004 04:51:27 GMT  
 What am I doing wrong?
Quote:
> Just add a line Me.Code.Undo to erase the user's input as part of the
> Else.

I thought that Cancel=True took care of that, so there would be nothing to
undo. I added Me.Code.Undo and it did not change anything. I tried it before
and after the cancel=true line.

Quote:

> Note that # is a wildcard, matching any numeric digit. If you want a
> letter followed by # you must use

> LIKE "[A-Z][#]"

My code without the brackets around the # works fine. I have tried all
possible entries, and it accepts any letter or any letter followed by any
single digit #. Note that I coppied this line from code that I believe u
originally gave to me in this ng:  Like "[A-Z][A-Z][A-Z]###" which has been
working exillently.

I am able to add code to deal with this extra message:
If Err.Number = 0 then
do not show message, just continue
end if
BUT something tells me that I should not have to do this. I have used this
code before, and cancel=true always finished it. Maybe since this is an
Index (required field) maybe this is the problem.



Sun, 22 Aug 2004 05:26:03 GMT  
 What am I doing wrong?
I found the problem:
The Field was Indexed, no dups. This means that it is required. This is not
the problem. Except that I also had the table property for this field set to
Required=Yes. This was the prob. Causes all sorts of strange ness. Like
after I got that second message and clicked ok. I could then tab out of that
field and save this incorrect entry. There were a few other strange things
occurring. As soon as I set this Indexed field to Required=No all was ok  :)

p


Quote:
> > Just add a line Me.Code.Undo to erase the user's input as part of the
> > Else.
> I thought that Cancel=True took care of that, so there would be nothing to
> undo. I added Me.Code.Undo and it did not change anything. I tried it
before
> and after the cancel=true line.

> > Note that # is a wildcard, matching any numeric digit. If you want a
> > letter followed by # you must use

> > LIKE "[A-Z][#]"
> My code without the brackets around the # works fine. I have tried all
> possible entries, and it accepts any letter or any letter followed by any
> single digit #. Note that I coppied this line from code that I believe u
> originally gave to me in this ng:  Like "[A-Z][A-Z][A-Z]###" which has
been
> working exillently.

> I am able to add code to deal with this extra message:
> If Err.Number = 0 then
> do not show message, just continue
> end if
> BUT something tells me that I should not have to do this. I have used this
> code before, and cancel=true always finished it. Maybe since this is an
> Index (required field) maybe this is the problem.



Sat, 28 Aug 2004 00:40:59 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Recordset: What am I doing wrong?

2. What am I doing wrong??

3. What am I doing wrong?

4. Help with syntax. What am I doing wrong

5. What am I doing wrong?

6. What am I doing wrong?

7. What am I doing wrong? -MultiSelect List box

8. Select Case - What am I doing wrong?

9. What am I doing wrong (easy).

10. OLE problem, or what am I doing wrong?

11. What am I doing wrong?

12. Footer/Page # - What am I doing wrong?

 

 
Powered by phpBB® Forum Software