473,405 Members | 2,287 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

If statement not working

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
7 1898
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
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Chris Tilley - HPC:Factor | last post by:
Hi, I'm utterly confounded by this one. There must be some sort of rule that I don't know of. I'd consider myself a Newbie+1, so be gentle. I have a database connection (working A-Ok) and a...
4
by: James E Koehler | last post by:
I can't get the WHILE statement to work in MySQL. The version of MySQL that I am using is: Ver 12.16 Distrib 4.0.6-gamma, for Win95/Win98 (i32) running on Windows MX. Here is the relevant...
1
by: mirandacascade | last post by:
O/S: Windows 2K Vsn of Python: 2.4 Currently: 1) Folder structure: \workarea\ <- ElementTree files reside here \xml\ \dom\
6
by: Doohan W. | last post by:
Hi, I'm now working with DB2, and I can't find out how to execute the contents of a string Statement, without using a Java/... procedure, only using SQL statements. I know that some SQBDs such...
7
by: mark | last post by:
Access 2000: I creating a report that has a record source built by the user who selects the WHERE values. An example is: SELECT * FROM CHARGELOG WHERE STDATE Between #10/27/2003# And...
4
by: kathy | last post by:
Working in a form, I have an Iif statement where if a date is not filled in, another field will show as a blank. If the date IS filled in, the 2nd field will show its actual value. The following...
3
by: Andy_Khosravi | last post by:
I have been trying to build a user friendly search engine for a small database I have created. I'm having some particular problems with one of my date fields. Here's the setup: I'm using...
14
by: Matt | last post by:
I need to add the following variable into an SQL statement and not sure how to do it. strGCID needs to be inserted into the following statement: SQL = "SELECT tblContacts.* FROM tblContacts...
2
by: travhale | last post by:
in a new project using .net 2005, c#. getting err message "Update requires a valid UpdateCommand when passed DataRow collection with modified rows." source RDBMS is oracle 8i. I add a new...
2
by: iulian.ilea | last post by:
What is wrong int this SQL statement? select top 10 DOCInt.*, DOCDet.* , Cate.*, Arti.*, .* from DOCInt INNER JOIN DOCDet ON DOCInt.CodDoc=DOCDet.CodDoc LEFT JOIN Cate ON...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.