If statement not working

If statement not working

am 08.01.2008 20:42:16 von BobH

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

Re: If statement not working

am 08.01.2008 21:00:17 von frogsteaks

On Jan 8, 2:42=A0pm, 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, =A0 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.

Re: If statement not working

am 08.01.2008 21:11:08 von Salad

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

Re: If statement not working

am 08.01.2008 21:16:58 von frogsteaks

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

Re: If statement not working

am 08.01.2008 21:32:44 von BobH

On Jan 8, 3:00=A0pm, frogste...@yahoo.com wrote:
> On Jan 8, 2:42=A0pm, 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, =A0 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. =A0Note that your test will ALWAYS be
> true. =A0The 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. =A0If one enters anythign else then both
> tests will be true. =A0Therefore the entire test will ALWAYS be true.
> Replace OR with AND.

Replacing the 'or' with an 'and' worked great, thanks for your
help :)
bobh.

Re: If statement not working

am 09.01.2008 00:20:08 von Salad

frogsteaks@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
>

Re: If statement not working

am 09.01.2008 04:33:00 von ImLouZer

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 <13o819af8polc60@corp.supernews.com>, oil@vinegar.com says...
> frogsteaks@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
> >
>

Re: If statement not working

am 09.01.2008 05:33:56 von Salad

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 <13o819af8polc60@corp.supernews.com>, oil@vinegar.com says...
>
>>frogsteaks@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
>>>
>>