472,342 Members | 1,445 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

Building a Where Clause Using PC/Zip as Criteria Item

I would really appreciate your assistance.

I am using Access 2000 to create a form that Lists Names and Addresses based
on a number of selection criteria one of which is a combo box cboPCZip. All
the selection criteria are used to build a Where clause (strWhere1).

If optBeginsContains = 1 Then 'Return records Beginning with the value in
cboPCZip
strWhere1 = strWhere1 & " And ((tblAddress.strPCZip) like """ & cboPCZip
& "*"")"
Else 'Return records Containing the value in cboPCZip
strWhere1 = strWhere1 & " And ((tblAddress.strPCZip) like """ & "*" &
cboPCZip & "*"")"
End If

Problem:
If cboPCZip is NOT a Number, i.e., 1234-4235 records are found and returned.
However if cboPCZip isNumeric, i.e., 12344235 no records are returned, even
though there are Address records where the PCZip field contains the zip code
12344235.

For Example:
This does NOT work: Where ((tblAddress.strPCZip) like "12344235*")
This does work: Where ((tblAddress.strPCZip) like "1234-4235*")

What am I doing wrong?

Thanks for your help!
Nov 12 '05 #1
4 1856
Barry,
Probably not a code problem. You've probably got junk data in your postal
codes. Some of your users have typed the same postal code in a variant form
and it is not matching your WHERE clause. Modifying the postal codes to
conform to a standard would be one solution but changing these could have
consequences for anything that has been written assuming the data remains as
it is. Better idea is to add a column to your table with the corrected
postal codes and have your code join on the new postal code column. Also
guard the new postal code column with vicious dogs so users don't create a
new issue by adding junk to that column as well.

"Barry Edmund Wright" <ba*****************@NOSPAMrogers.com> wrote in
message news:hS************@twister01.bloor.is.net.cable.r ogers.com...
I would really appreciate your assistance.

I am using Access 2000 to create a form that Lists Names and Addresses based on a number of selection criteria one of which is a combo box cboPCZip. All the selection criteria are used to build a Where clause (strWhere1).

If optBeginsContains = 1 Then 'Return records Beginning with the value in
cboPCZip
strWhere1 = strWhere1 & " And ((tblAddress.strPCZip) like """ & cboPCZip & "*"")"
Else 'Return records Containing the value in cboPCZip
strWhere1 = strWhere1 & " And ((tblAddress.strPCZip) like """ & "*" &
cboPCZip & "*"")"
End If

Problem:
If cboPCZip is NOT a Number, i.e., 1234-4235 records are found and returned. However if cboPCZip isNumeric, i.e., 12344235 no records are returned, even though there are Address records where the PCZip field contains the zip code 12344235.

For Example:
This does NOT work: Where ((tblAddress.strPCZip) like "12344235*")
This does work: Where ((tblAddress.strPCZip) like "1234-4235*")

What am I doing wrong?

Thanks for your help!

Nov 12 '05 #2
"Barry Edmund Wright" <ba*****************@NOSPAMrogers.com> wrote in
message news:hS************@twister01.bloor.is.net.cable.r ogers.com...
I would really appreciate your assistance.

I am using Access 2000 to create a form that Lists Names and Addresses based on a number of selection criteria one of which is a combo box cboPCZip. All the selection criteria are used to build a Where clause (strWhere1).

If optBeginsContains = 1 Then 'Return records Beginning with the value in
cboPCZip
strWhere1 = strWhere1 & " And ((tblAddress.strPCZip) like """ & cboPCZip & "*"")"
Else 'Return records Containing the value in cboPCZip
strWhere1 = strWhere1 & " And ((tblAddress.strPCZip) like """ & "*" &
cboPCZip & "*"")"
End If

Problem:
If cboPCZip is NOT a Number, i.e., 1234-4235 records are found and returned. However if cboPCZip isNumeric, i.e., 12344235 no records are returned, even though there are Address records where the PCZip field contains the zip code 12344235.

For Example:
This does NOT work: Where ((tblAddress.strPCZip) like "12344235*")
This does work: Where ((tblAddress.strPCZip) like "1234-4235*")

What am I doing wrong?

Thanks for your help!


I suspec tthe LIKE operator only works for strings/text? When you insert a
dash (-) Access probably assumes it is a string.

Maybe insert some single quotes around your value?

Where ((tblAddress.strPCZip) like "'12344235*'")
--
Bradley
Software Developer www.hrsystems.com.au
A Christian Response www.pastornet.net.au/response
Nov 12 '05 #3
Thanks you your response Alan.

Even though the data in the field was OK your response made look deeper,
specifically, the cboPCZip.rowsource code. There I found an error which was
returning an incorrect value which of course it couldn't find because the
value was not in the database field strPCZip that the combo box was based
on.

"Alan Webb" <kn*****@hotmail.com> wrote in message
news:g2*****************@news.uswest.net...
Barry,
Probably not a code problem. You've probably got junk data in your postal
codes. Some of your users have typed the same postal code in a variant form and it is not matching your WHERE clause. Modifying the postal codes to
conform to a standard would be one solution but changing these could have
consequences for anything that has been written assuming the data remains as it is. Better idea is to add a column to your table with the corrected
postal codes and have your code join on the new postal code column. Also
guard the new postal code column with vicious dogs so users don't create a
new issue by adding junk to that column as well.

"Barry Edmund Wright" <ba*****************@NOSPAMrogers.com> wrote in
message news:hS************@twister01.bloor.is.net.cable.r ogers.com...
I would really appreciate your assistance.

I am using Access 2000 to create a form that Lists Names and Addresses

based
on a number of selection criteria one of which is a combo box cboPCZip.

All
the selection criteria are used to build a Where clause (strWhere1).

If optBeginsContains = 1 Then 'Return records Beginning with the value in cboPCZip
strWhere1 = strWhere1 & " And ((tblAddress.strPCZip) like """ &

cboPCZip
& "*"")"
Else 'Return records Containing the value in cboPCZip
strWhere1 = strWhere1 & " And ((tblAddress.strPCZip) like """ & "*" &
cboPCZip & "*"")"
End If

Problem:
If cboPCZip is NOT a Number, i.e., 1234-4235 records are found and

returned.
However if cboPCZip isNumeric, i.e., 12344235 no records are returned,

even
though there are Address records where the PCZip field contains the zip

code
12344235.

For Example:
This does NOT work: Where ((tblAddress.strPCZip) like "12344235*")
This does work: Where ((tblAddress.strPCZip) like "1234-4235*")

What am I doing wrong?

Thanks for your help!


Nov 12 '05 #4
Thank you for your response Bradley.
I actually found the error to be in the SQL string used as the cboPCZip.recordsource.

Bradley, I looked at the web sites you have developed and was facinated by the fact that they are based on, I presume, an Access
database; I beleive the Access Web also uses this technique. Could you give me some information on how you learned to do this, i.e.,
books read, courses taken, articles read, etc.

I would really appreciate hearing back from you.
--
Barry Edmund Wright
Microsoft Access Developer

301-100 Spadina Rd.
Toronto, Ontario M5R 2T7
Phone: 1-416-921-7082
E-mail: ba*****************@NOSPAMrogers.com

"Bradley" <br*****@REMOVETHIScomcen.com.au> wrote in message news:40******@nexus.comcen.com.au...
"Barry Edmund Wright" <ba*****************@NOSPAMrogers.com> wrote in
message news:hS************@twister01.bloor.is.net.cable.r ogers.com...
I would really appreciate your assistance.

I am using Access 2000 to create a form that Lists Names and Addresses based on a number of selection criteria one of which is a combo box cboPCZip. All the selection criteria are used to build a Where clause (strWhere1).

If optBeginsContains = 1 Then 'Return records Beginning with the value in
cboPCZip
strWhere1 = strWhere1 & " And ((tblAddress.strPCZip) like """ & cboPCZip & "*"")"
Else 'Return records Containing the value in cboPCZip
strWhere1 = strWhere1 & " And ((tblAddress.strPCZip) like """ & "*" &
cboPCZip & "*"")"
End If

Problem:
If cboPCZip is NOT a Number, i.e., 1234-4235 records are found and returned. However if cboPCZip isNumeric, i.e., 12344235 no records are returned, even though there are Address records where the PCZip field contains the zip code 12344235.

For Example:
This does NOT work: Where ((tblAddress.strPCZip) like "12344235*")
This does work: Where ((tblAddress.strPCZip) like "1234-4235*")

What am I doing wrong?

Thanks for your help!


I suspec tthe LIKE operator only works for strings/text? When you insert a
dash (-) Access probably assumes it is a string.

Maybe insert some single quotes around your value?

Where ((tblAddress.strPCZip) like "'12344235*'")
--
Bradley
Software Developer www.hrsystems.com.au
A Christian Response www.pastornet.net.au/response

Nov 12 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: A.V.C. | last post by:
Hello, I found members of this group very helpful for my last queries. Have one problem with CASE. I can use the column name alias in Order By...
2
by: Ellen Manning | last post by:
Using A2K. In my table I have the field "Grant" which can have a value or be null. I have a query that counts the number of records and has a...
1
by: BerkshireGuy | last post by:
Hello everyone, I am reading a query's SQL string and adding criteria to that and then resaving it. I know, might not be the best method, but it...
4
by: Brian Shannon | last post by:
I have 3 combo boxes and two date text boxes on a .aspx page. The user can fill in any of the 5 controls or none to filter a datagrid. I was...
9
by: DFS | last post by:
You might also find other uses ========================================================= Public Function getSelections(selType As String,...
5
by: WebMatrix | last post by:
Hello, I am developing ASP.NET 1.1 application against SQL Server 2000 db, where users have ability to construct their own select criteria (for a...
2
by: Jim.Mueksch | last post by:
I am having a problem with using calculated values in a WHERE clause. My query is below. DB2 gives me this error message: Error: SQL0206N...
1
by: 2D Rick | last post by:
I want to open a report using OpenReport and passing it a Where Clause with multiple criteria. I know the Where Clause below is way off but it...
1
by: mtnbikur | last post by:
Lots of reading out there says you should only place “join criteria” in the join clause. That makes perfect sense. What about other search...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...

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.