By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,635 Members | 911 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,635 IT Pros & Developers. It's quick & easy.

If statement not working

P: n/a
Hi All,

In AccessXP I created this if statement

If Me!bxEntryTyp <"pe" Or "ptu" Then

and when it runs I get a 'Type Mismatch' error, why??

I tried If Me!bxEntryTyp <"pe" Or Me!bxEntryTyp <"ptu" Then
and that did not work either

the bxEntryTyp on the form does not have a format applied to it and
the field's datatype in the table is 'Text'

thanks

Jan 8 '08 #1
Share this Question
Share on Google+
7 Replies


P: n/a
On Jan 8, 2:42*pm, bobh <vulca...@yahoo.comwrote:
Hi All,

In AccessXP I created this if statement

If Me!bxEntryTyp <"pe" Or "ptu" Then

and when it runs I get a 'Type Mismatch' error, * why??

I tried If Me!bxEntryTyp <"pe" Or Me!bxEntryTyp <"ptu" Then
and that did not work either

the bxEntryTyp on the form does not have a format applied to it and
the field's datatype in the table is 'Text'

thanks
try testing me!bxentrytyp.value. Note that your test will ALWAYS be
true. The entry will ALWAYS not be equal to one of those two values.
If one enters "PE" then the 2nd test will be true, if one enters "ptu"
then the 1st test will be true. If one enters anythign else then both
tests will be true. Therefore the entire test will ALWAYS be true.
Replace OR with AND.
Jan 8 '08 #2

P: n/a
bobh wrote:
Hi All,

In AccessXP I created this if statement

If Me!bxEntryTyp <"pe" Or "ptu" Then

and when it runs I get a 'Type Mismatch' error, why??

I tried If Me!bxEntryTyp <"pe" Or Me!bxEntryTyp <"ptu" Then
and that did not work either

the bxEntryTyp on the form does not have a format applied to it and
the field's datatype in the table is 'Text'

thanks
In the first case, because you aren't comparing "ptu" to anything. It'd
be nice if we could write shortcut code like that but we can't.

Here's a quick routine I wrote
Dim b
Dim i As Integer
Dim a(3) As String
a(0) = "Joe"
a(1) = "Sam"
a(2) = "Sally"

For i = 0 To 2
b = a(i)
If b <"Joe" Or b <"Sam" Then
MsgBox "If " & b
Else
MsgBox "Else & b"
End If
Next

It will never execute the Esle section. Here's the table of the For loop
True False = True
False True = True
True True = True

I think you want to use And instead of OR.

Melanesia
http://www.youtube.com/watch?v=Fmz5NXmAJMQ
Jan 8 '08 #3

P: n/a
Wow thats a load of coding for a simple IF.
if ( (Me.tbFirstTextBox.Value <"Foo") AND (Me.tbSecondTextBox.Value
<"Bar") ) Then
Code if user entered neither "Foo" nor "Bar"
else
Code if user entered either "Foo" or "Bar"
endif

Jan 8 '08 #4

P: n/a
On Jan 8, 3:00*pm, frogste...@yahoo.com wrote:
On Jan 8, 2:42*pm, bobh <vulca...@yahoo.comwrote:
Hi All,
In AccessXP I created this if statement
If Me!bxEntryTyp <"pe" Or "ptu" Then
and when it runs I get a 'Type Mismatch' error, * why??
I tried If Me!bxEntryTyp <"pe" Or Me!bxEntryTyp <"ptu" Then
and that did not work either
the bxEntryTyp on the form does not have a format applied to it and
the field's datatype in the table is 'Text'
thanks

try testing me!bxentrytyp.value. *Note that your test will ALWAYS be
true. *The entry will ALWAYS not be equal to one of those two values.
If one enters "PE" then the 2nd test will be true, if one enters "ptu"
then the 1st test will be true. *If one enters anythign else then both
tests will be true. *Therefore the entire test will ALWAYS be true.
Replace OR with AND.
Replacing the 'or' with an 'and' worked great, thanks for your
help :)
bobh.
Jan 8 '08 #5

P: n/a
fr********@yahoo.com wrote:
Wow thats a load of coding for a simple IF.
If you say so. All I see in your example below is aircode that won't
run or produce results.

I provided an example with 3 different values that demonstrated all
possible actions. I did leave off the Sub/EndSub. That probably
confused you.

I did notice we both mentioned the fact the If compare would always be
true. Congratulations.

I noticed you were seeking help for a report in another post. Three
suggestions.

First suggestion, create a main report. Then create a sub report. The
subreport will list the categories. Make it a multi-column report going
accoss then down. It will look much neater than your desired
"CategoryName01, CategoryName03, CategoryName04"

Second suggestion if you want the unclean look. Create a function. No
code provided. Create a textbox in your detail or whatever band and
enter something like
=GetCategoryList([VendorID])
You pass the ID to the function and the function selects all Category
records for that VendorID. The function then scans all categories in
the recordset and concatenates them to the GetCategoryList variable and
returns this list back to the text field.

Third suggestion. Don't be a wiseass.
Yeehaw!
http://www.youtube.com/watch?v=ELJJbkuewi8

>
if ( (Me.tbFirstTextBox.Value <"Foo") AND (Me.tbSecondTextBox.Value
<"Bar") ) Then
Code if user entered neither "Foo" nor "Bar"
else
Code if user entered either "Foo" or "Bar"
endif
Jan 8 '08 #6

P: n/a
The man wanted to know whether or not the text entered into a given text
box control was equal to one of two hard coded values. That is exactly
what the code frog wrote does. It accomplishes the same thing that your
codes does but its not rube goldberg code. I think the other guys code
was much cleaner. Nothing was confusing at all in your example but it
was way over coded for the question asked.

I'll let frog respond to your wiseass comments except to say he wasnt
being one at all.

In article <13*************@corp.supernews.com>, oi*@vinegar.com says...
fr********@yahoo.com wrote:
Wow thats a load of coding for a simple IF.
If you say so. All I see in your example below is aircode that won't
run or produce results.

I provided an example with 3 different values that demonstrated all
possible actions. I did leave off the Sub/EndSub. That probably
confused you.

I did notice we both mentioned the fact the If compare would always be
true. Congratulations.

I noticed you were seeking help for a report in another post. Three
suggestions.

First suggestion, create a main report. Then create a sub report. The
subreport will list the categories. Make it a multi-column report going
accoss then down. It will look much neater than your desired
"CategoryName01, CategoryName03, CategoryName04"

Second suggestion if you want the unclean look. Create a function. No
code provided. Create a textbox in your detail or whatever band and
enter something like
=GetCategoryList([VendorID])
You pass the ID to the function and the function selects all Category
records for that VendorID. The function then scans all categories in
the recordset and concatenates them to the GetCategoryList variable and
returns this list back to the text field.

Third suggestion. Don't be a wiseass.
Yeehaw!
http://www.youtube.com/watch?v=ELJJbkuewi8


if ( (Me.tbFirstTextBox.Value <"Foo") AND (Me.tbSecondTextBox.Value
<"Bar") ) Then
Code if user entered neither "Foo" nor "Bar"
else
Code if user entered either "Foo" or "Bar"
endif
Jan 9 '08 #7

P: n/a
ImLouZer wrote:
The man wanted to know whether or not the text entered into a given text
box control was equal to one of two hard coded values. That is exactly
what the code frog wrote does. It accomplishes the same thing that your
codes does but its not rube goldberg code. I think the other guys code
was much cleaner. Nothing was confusing at all in your example but it
was way over coded for the question asked.
I get a message from a Louzer (apt name I might add) telling me how I
should answer questions in a newsgroup. You have 1 message in this
newsgroup, the post I am responding to, and it didn't help anyone. I
have been with this group since 97 and helped many. Frankly, I'm going
to ignore a Louzer's advice.
I'll let frog respond to your wiseass comments except to say he wasnt
being one at all.
Louzer, I made amends and helped him out with a problem he was having
that nobody else has responded to his post at this time. If a frog that
has been here for one day wants to take umbrage, I could care less.

Loser
http://www.youtube.com/watch?v=KynpC1e9I9E
>
In article <13*************@corp.supernews.com>, oi*@vinegar.com says...
>>fr********@yahoo.com wrote:

>>>Wow thats a load of coding for a simple IF.

If you say so. All I see in your example below is aircode that won't
run or produce results.

I provided an example with 3 different values that demonstrated all
possible actions. I did leave off the Sub/EndSub. That probably
confused you.

I did notice we both mentioned the fact the If compare would always be
true. Congratulations.

I noticed you were seeking help for a report in another post. Three
suggestions.

First suggestion, create a main report. Then create a sub report. The
subreport will list the categories. Make it a multi-column report going
accoss then down. It will look much neater than your desired
"CategoryName01, CategoryName03, CategoryName04"

Second suggestion if you want the unclean look. Create a function. No
code provided. Create a textbox in your detail or whatever band and
enter something like
=GetCategoryList([VendorID])
You pass the ID to the function and the function selects all Category
records for that VendorID. The function then scans all categories in
the recordset and concatenates them to the GetCategoryList variable and
returns this list back to the text field.

Third suggestion. Don't be a wiseass.
Yeehaw!
http://www.youtube.com/watch?v=ELJJbkuewi8
>>>if ( (Me.tbFirstTextBox.Value <"Foo") AND (Me.tbSecondTextBox.Value
<"Bar") ) Then
Code if user entered neither "Foo" nor "Bar"
else
Code if user entered either "Foo" or "Bar"
endif
Jan 9 '08 #8

This discussion thread is closed

Replies have been disabled for this discussion.