Hi All,
Can you see anything wrong with the below code? I'm trying to make sure that if the State in the record is VA, that the area code is either 703 or 804. When I test, no matter what I change the first 3 integers of the phone number to, I get the error msg box. Even if it's 703 or 804, I still get the error box. Any help would be appreciated. Thanks. - Private Sub Form_BeforeUpdate(Cancel As Integer)
-
'Verify the correct area code for VA
-
Dim AreaCode As Integer
-
If Not IsNull([State]) And Not IsNull([Phone]) Then
-
AreaCode = Val(Left([Phone], 3))
-
Select Case [State]
-
Case "VA"
-
If AreaCode <> "703" Or AreaCode <> "804" Then
-
DoCmd.CancelEvent
-
MsgBox "Area Code must be 703 or 804"
-
Phone.SetFocus
-
End If
-
End Select
-
End If
-
-
End Sub
5 1221
Just a slight change in Logic should do the trick: - 'Verify the correct area code for VA
-
Dim AreaCode As Integer
-
-
If Not IsNull([State]) And Not IsNull([Phone]) Then
-
AreaCode = Val(Left([Phone], 3))
-
Else
-
Exit Sub
-
End If
-
-
Select Case [State]
-
Case "VA"
-
Select Case AreaCode
-
Case 703, 804
-
'do nothing
-
Case Else
-
MsgBox "Area Code must be 703 or 804"
-
Me![Phone].SetFocus
-
End Select
-
Case Else
-
'States other than 'VA'
-
End Select
P.S. - The Expression - If AreaCode <> "703" Or AreaCode <> "804"
will never evaluate to TRUE even if AreaCode = 703 or 804 since it cannot be equal to both at the same time.
Your problem is in the line - If AreaCode <> "703" Or AreaCode <> "804" Then
Because you used the OR comparison, only one side has to be true for the If/Then to follow the true side. So if you enter 703, the first side is false but the second side is true, so your code will produce the message box. If you used the AND comparison, then both sides would have to return true for the true path to be taken. Thus, if you enter 703, then the first side returns false and makes the whole test return false.
Thank you ADezii, That worked perfectly. I don't know why the <> didn't work, but I'm glad you found a way to make it work. Thanks again.
Thank you Seth for the insight. That worked with my original code. I guess I need to be more careful with my comparison operators. Thanks for pointing that out.
I don't know why the <> didn't work
It is simply a matter of Syntax. - '************** Code Intentionally omitted **************
-
Select Case [State]
-
Case "VA"
-
If (AreaCode <> 703) And (AreaCode <> 804) Then
-
MsgBox "Area Code must be 703 or 804"
-
Me![Phone].SetFocus
-
End If
-
Case Else
-
'States other than 'VA'
-
End Select
will work.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Brian Loesgen |
last post by:
The next San Diego .Net User Group meeting is Tuesday, November 25,
2003 at the Scripps Ranch Library.
Scripps Ranch Library
10301 Scripps Lake Drive
San Diego, CA 92131-1026
Please join us...
|
by: gmesmer |
last post by:
Hello
I have created an assembly to print a pdf document and I wrote some unit tests and everything works from within nuint and cruisecontrol.net. ( I am using C#)
Next I have to put together a...
|
by: Namratha Shah \(Nasha\) |
last post by:
Hey Guys,
Today we are going to look at Code Access Security.
Code access security is a feature of .NET that manages code depending on its
trust level. If the CLS trusts the code enough to...
|
by: MS News \(MS ILM\) |
last post by:
Hello,
How do I add some JavaScript into my Response
and make the page scroll to some specific area on my page in the Browser
when tired few thing it did not work at all
Any help and sample...
|
by: Charlie |
last post by:
Hi:
After posting back, I would like to return to a specific area of page. For
example, when my "add to cart" handler posts back, I would like returned
page to scroll to where button was...
|
by: Ricky Kam |
last post by:
I'm using MODI, after the document is OCR, is there a way to select a word in
a specific area? I know it can be done if someone use the mouse and do the
selection manually, but if I want to achieve...
|
by: Abel Chan |
last post by:
Hi there,
I am trying to use ASP.NET to populate list of files with hyper link from a
specific directory. The following code works well but it populates the list
to the top of the web page. I...
|
by: =?Utf-8?B?TWlrZSBNY0FsbGlzdGVy?= |
last post by:
First, I'm not an AD Administrator. However, I have an important business
need to be able to learn and pass along information about configuring .NET
Code Access Security from Active Directory.
...
|
by: deknoopjes |
last post by:
I want to display a specific area of an external website using iFrames. A year ago I created such code successfully, but lost this code due to a crashed computer. Googling for any solutions did not...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |