473,388 Members | 1,209 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,388 software developers and data experts.

"Like" in Query String

Hello All!

I am using the following code during an On Click event for a button.
It works properly to create a query for a report:

Private Sub Command14_Click()
If IsNull(Me.Text30) Then
' No criteria here - so ignore
Else
strWhere = strWhere & ",'" & Me.Text30.Value & "'"
End If
If IsNull(Me.Text31) Then
' No criteria here - so ignore
Else
strWhere = strWhere & ",'" & Me.Text31.Value & "'"
End If
If IsNull(Me.Text32) Then
' No criteria here - so ignore
Else
strWhere = strWhere & ",'" & Me.Text32.Value & "'"
End If
If IsNull(Me.Text33) Then
' No criteria here - so ignore
Else
strWhere = strWhere & ",'" & Me.Text33.Value & "'"
End If

If IsNull(Me.Text34) Then
' No criteria here - so ignore
Else
strWhere = strWhere & ",'" & Me.Text34.Value & "'"
End If

If IsNull(Me.Text35) Then
' No criteria here - so ignore
Else
strWhere = strWhere & ",'" & Me.Text35.Value & "'"
End If

If IsNull(Me.Text36) Then
' No criteria here - so ignore
Else
strWhere = strWhere & ",'" & Me.Text36.Value & "'"
End If

If IsNull(Me.Text37) Then
' No criteria here - so ignore
Else
strWhere = strWhere & ",'" & Me.Text37.Value & "'"
End If
If Len(strWhere) 1 Then

strWhere = Mid$(strWhere, 2)
strWhere = "AC IN (" & strWhere & ")"
'strWhere = "" & strLike & " AC IN (" & strWhere & ")"
End If

DoCmd.OpenReport "qryAm", acViewPreview, , strWhere
End Sub

----------------------------------

The line I would specifically like to ask about is the following:

strWhere = "AC IN (" & strWhere & ")"

How would I include a "Like" in the string?
Psuedocode - AC IN LIKE *strWhwere*

Thank you in advance!

Brad

Nov 30 '06 #1
9 2421
Drum2001 wrote:
Hello All!

I am using the following code during an On Click event for a button.
It works properly to create a query for a report:

Private Sub Command14_Click()
If IsNull(Me.Text30) Then
' No criteria here - so ignore
Else
strWhere = strWhere & ",'" & Me.Text30.Value & "'"
End If
If IsNull(Me.Text31) Then
' No criteria here - so ignore
Else
strWhere = strWhere & ",'" & Me.Text31.Value & "'"
End If
If IsNull(Me.Text32) Then
' No criteria here - so ignore
Else
strWhere = strWhere & ",'" & Me.Text32.Value & "'"
End If
If IsNull(Me.Text33) Then
' No criteria here - so ignore
Else
strWhere = strWhere & ",'" & Me.Text33.Value & "'"
End If

If IsNull(Me.Text34) Then
' No criteria here - so ignore
Else
strWhere = strWhere & ",'" & Me.Text34.Value & "'"
End If

If IsNull(Me.Text35) Then
' No criteria here - so ignore
Else
strWhere = strWhere & ",'" & Me.Text35.Value & "'"
End If

If IsNull(Me.Text36) Then
' No criteria here - so ignore
Else
strWhere = strWhere & ",'" & Me.Text36.Value & "'"
End If

If IsNull(Me.Text37) Then
' No criteria here - so ignore
Else
strWhere = strWhere & ",'" & Me.Text37.Value & "'"
End If
If Len(strWhere) 1 Then

strWhere = Mid$(strWhere, 2)
strWhere = "AC IN (" & strWhere & ")"
'strWhere = "" & strLike & " AC IN (" & strWhere & ")"
End If

DoCmd.OpenReport "qryAm", acViewPreview, , strWhere
End Sub

----------------------------------

The line I would specifically like to ask about is the following:

strWhere = "AC IN (" & strWhere & ")"

How would I include a "Like" in the string?
Psuedocode - AC IN LIKE *strWhwere*

Thank you in advance!

Brad
Why not make your query use ORs instead
StrWhere = AC Like "Test*" Or
AC Like "Question*" Or
AC Like "Answer*"

Nov 30 '06 #2
Would that be static?

Users are not always going to enter information in every textbox.

If not, how would I exactly code the strWhere?
salad wrote:
Drum2001 wrote:
Hello All!

I am using the following code during an On Click event for a button.
It works properly to create a query for a report:

Private Sub Command14_Click()
If IsNull(Me.Text30) Then
' No criteria here - so ignore
Else
strWhere = strWhere & ",'" & Me.Text30.Value & "'"
End If
If IsNull(Me.Text31) Then
' No criteria here - so ignore
Else
strWhere = strWhere & ",'" & Me.Text31.Value & "'"
End If
If IsNull(Me.Text32) Then
' No criteria here - so ignore
Else
strWhere = strWhere & ",'" & Me.Text32.Value & "'"
End If
If IsNull(Me.Text33) Then
' No criteria here - so ignore
Else
strWhere = strWhere & ",'" & Me.Text33.Value & "'"
End If

If IsNull(Me.Text34) Then
' No criteria here - so ignore
Else
strWhere = strWhere & ",'" & Me.Text34.Value & "'"
End If

If IsNull(Me.Text35) Then
' No criteria here - so ignore
Else
strWhere = strWhere & ",'" & Me.Text35.Value & "'"
End If

If IsNull(Me.Text36) Then
' No criteria here - so ignore
Else
strWhere = strWhere & ",'" & Me.Text36.Value & "'"
End If

If IsNull(Me.Text37) Then
' No criteria here - so ignore
Else
strWhere = strWhere & ",'" & Me.Text37.Value & "'"
End If
If Len(strWhere) 1 Then

strWhere = Mid$(strWhere, 2)
strWhere = "AC IN (" & strWhere & ")"
'strWhere = "" & strLike & " AC IN (" & strWhere & ")"
End If

DoCmd.OpenReport "qryAm", acViewPreview, , strWhere
End Sub

----------------------------------

The line I would specifically like to ask about is the following:

strWhere = "AC IN (" & strWhere & ")"

How would I include a "Like" in the string?
Psuedocode - AC IN LIKE *strWhwere*

Thank you in advance!

Brad
Why not make your query use ORs instead
StrWhere = AC Like "Test*" Or
AC Like "Question*" Or
AC Like "Answer*"
Nov 30 '06 #3
Drum2001 wrote:
Would that be static?

Users are not always going to enter information in every textbox.

If not, how would I exactly code the strWhere?
salad wrote:
>>Drum2001 wrote:

>>>Hello All!

I am using the following code during an On Click event for a button.
It works properly to create a query for a report:

Private Sub Command14_Click()
If IsNull(Me.Text30) Then
' No criteria here - so ignore
Else
strWhere = strWhere & ",'" & Me.Text30.Value & "'"
End If
If IsNull(Me.Text31) Then
' No criteria here - so ignore
Else
strWhere = strWhere & ",'" & Me.Text31.Value & "'"
End If
If IsNull(Me.Text32) Then
' No criteria here - so ignore
Else
strWhere = strWhere & ",'" & Me.Text32.Value & "'"
End If
If IsNull(Me.Text33) Then
' No criteria here - so ignore
Else
strWhere = strWhere & ",'" & Me.Text33.Value & "'"
End If

If IsNull(Me.Text34) Then
' No criteria here - so ignore
Else
strWhere = strWhere & ",'" & Me.Text34.Value & "'"
End If

If IsNull(Me.Text35) Then
' No criteria here - so ignore
Else
strWhere = strWhere & ",'" & Me.Text35.Value & "'"
End If

If IsNull(Me.Text36) Then
' No criteria here - so ignore
Else
strWhere = strWhere & ",'" & Me.Text36.Value & "'"
End If

If IsNull(Me.Text37) Then
' No criteria here - so ignore
Else
strWhere = strWhere & ",'" & Me.Text37.Value & "'"
End If
If Len(strWhere) 1 Then

strWhere = Mid$(strWhere, 2)
strWhere = "AC IN (" & strWhere & ")"
'strWhere = "" & strLike & " AC IN (" & strWhere & ")"
End If

DoCmd.OpenReport "qryAm", acViewPreview, , strWhere
End Sub

----------------------------------

The line I would specifically like to ask about is the following:

strWhere = "AC IN (" & strWhere & ")"

How would I include a "Like" in the string?
Psuedocode - AC IN LIKE *strWhwere*

Thank you in advance!

Brad

Why not make your query use ORs instead
StrWhere = AC Like "Test*" Or
AC Like "Question*" Or
AC Like "Answer*"

Looking at the code you have up above you do check 3 or 4 checkboxes.
If Not IsNull(x) Then
strWhere = "AC Like '" & x & "' Or "
ENdif
If Not IsNull(y) Then
strWhere = "AC Like '" & y & "' Or "
ENdif
'remove the OR
strWhere = Left(strWhere,Len(strWHere)-4)
Nov 30 '06 #4
When I use this code, it only searches one textbox. It is the one that
it uses last.. Seems like its overwrighting. This is what I have:

------------------------------------------------------------------------------------------------
Private Sub Command14_Click()
If Not IsNull(Me.Text30) Then
strWHere = "ACLike '" & Me.Text30 & "*" & "' Or "
End If

If Not IsNull(Me.Text31) Then
strWHere = "ACLike '" & Me.Text31 & "*" & "' Or "
End If

If Not IsNull(Me.Text32) Then
strWHere = "AC Like '" & Me.Text32 & "*" & "' Or "
End If

If Not IsNull(Me.Text33) Then
strWHere = "ACLike '" & Me.Text33 & "*" & "' Or "
End If

If Not IsNull(Me.Text34) Then
strWHere = "AC Like '" & Me.Text34 & "*" & "' Or "
End If

If Not IsNull(Me.Text35) Then
strWHere = "AC Like '" & Me.Text35 & "*" & "' Or "
End If

If Not IsNull(Me.Text36) Then
strWHere = "AC Like '" & Me.Text36 & "*" & "' Or "
End If

If Not IsNull(Me.Text37) Then
strWHere = "AC Like '" & Me.Text37 & "'"
End If
'remove the OR
strWHere = Left(strWHere, Len(strWHere) - 4)
DoCmd.OpenReport "qryAcronym", acViewPreview, , strWHere

End Sub

------------------------------------------------------------------------------------------------

Any suggestions? I really appreciate your assistance!

Brad
salad wrote:
Drum2001 wrote:
Would that be static?

Users are not always going to enter information in every textbox.

If not, how would I exactly code the strWhere?
salad wrote:
>Drum2001 wrote:
Hello All!

I am using the following code during an On Click event for a button.
It works properly to create a query for a report:

Private Sub Command14_Click()
If IsNull(Me.Text30) Then
' No criteria here - so ignore
Else
strWhere = strWhere & ",'" & Me.Text30.Value & "'"
End If
If IsNull(Me.Text31) Then
' No criteria here - so ignore
Else
strWhere = strWhere & ",'" & Me.Text31.Value & "'"
End If
If IsNull(Me.Text32) Then
' No criteria here - so ignore
Else
strWhere = strWhere & ",'" & Me.Text32.Value & "'"
End If
If IsNull(Me.Text33) Then
' No criteria here - so ignore
Else
strWhere = strWhere & ",'" & Me.Text33.Value & "'"
End If

If IsNull(Me.Text34) Then
' No criteria here - so ignore
Else
strWhere = strWhere & ",'" & Me.Text34.Value & "'"
End If

If IsNull(Me.Text35) Then
' No criteria here - so ignore
Else
strWhere = strWhere & ",'" & Me.Text35.Value & "'"
End If

If IsNull(Me.Text36) Then
' No criteria here - so ignore
Else
strWhere = strWhere & ",'" & Me.Text36.Value & "'"
End If

If IsNull(Me.Text37) Then
' No criteria here - so ignore
Else
strWhere = strWhere & ",'" & Me.Text37.Value & "'"
End If
If Len(strWhere) 1 Then

strWhere = Mid$(strWhere, 2)
strWhere = "AC IN (" & strWhere & ")"
'strWhere = "" & strLike & " AC IN (" & strWhere & ")"
End If

DoCmd.OpenReport "qryAm", acViewPreview, , strWhere
End Sub

----------------------------------

The line I would specifically like to ask about is the following:

strWhere = "AC IN (" & strWhere & ")"

How would I include a "Like" in the string?
Psuedocode - AC IN LIKE *strWhwere*

Thank you in advance!

Brad
Why not make your query use ORs instead
StrWhere = AC Like "Test*" Or
AC Like "Question*" Or
AC Like "Answer*"
Looking at the code you have up above you do check 3 or 4 checkboxes.
If Not IsNull(x) Then
strWhere = "AC Like '" & x & "' Or "
ENdif
If Not IsNull(y) Then
strWhere = "AC Like '" & y & "' Or "
ENdif
'remove the OR
strWhere = Left(strWhere,Len(strWHere)-4)
Dec 1 '06 #5

Drum2001 wrote:
When I use this code, it only searches one textbox. It is the one that
it uses last.. Seems like its overwrighting. This is what I have:

------------------------------------------------------------------------------------------------
Private Sub Command14_Click()
If Not IsNull(Me.Text30) Then
strWHere = "ACLike '" & Me.Text30 & "*" & "' Or "
End If

If Not IsNull(Me.Text31) Then
strWHere = "ACLike '" & Me.Text31 & "*" & "' Or "
End If

If Not IsNull(Me.Text32) Then
strWHere = "AC Like '" & Me.Text32 & "*" & "' Or "
End If

If Not IsNull(Me.Text33) Then
strWHere = "ACLike '" & Me.Text33 & "*" & "' Or "
End If

If Not IsNull(Me.Text34) Then
strWHere = "AC Like '" & Me.Text34 & "*" & "' Or "
End If

If Not IsNull(Me.Text35) Then
strWHere = "AC Like '" & Me.Text35 & "*" & "' Or "
End If

If Not IsNull(Me.Text36) Then
strWHere = "AC Like '" & Me.Text36 & "*" & "' Or "
End If

If Not IsNull(Me.Text37) Then
strWHere = "AC Like '" & Me.Text37 & "'"
End If
'remove the OR
strWHere = Left(strWHere, Len(strWHere) - 4)
DoCmd.OpenReport "qryAcronym", acViewPreview, , strWHere

End Sub

------------------------------------------------------------------------------------------------

Any suggestions? I really appreciate your assistance!

Brad
You need to replace "strWHere = " with "strWHere = strWhere & " in your
code.

Bruce

Dec 1 '06 #6
Drum2001 wrote:
When I use this code, it only searches one textbox. It is the one that
it uses last.. Seems like its overwrighting. This is what I have:

------------------------------------------------------------------------------------------------
Private Sub Command14_Click()
If Not IsNull(Me.Text30) Then
strWHere = "ACLike '" & Me.Text30 & "*" & "' Or "
End If

If Not IsNull(Me.Text31) Then
strWHere = "ACLike '" & Me.Text31 & "*" & "' Or "
End If
<snip>

First of all your form object naming convention, or lack of one sucks. 8)

But to address your problem, your code is rewriting the whole of
strWhere everytime an if statement is executed. To fix what you have,
on the second if statement shown above, and all the remaining ones replace:

strWHere = "ACLike '" & Me.Text31 & "*" & "' Or "

with

strWHere = strwhere & "ACLike '" & Me.Text31 & "*" & "' Or "

That will do it.
--
Tim http://www.ucs.mun.ca/~tmarshal/
^o<
/#) "Burp-beep, burp-beep, burp-beep?" - Quaker Jake
/^^ "Be Careful, Big Bird!" - Ditto "TIM-MAY!!" - Me
Dec 1 '06 #7
Tim Marshall wrote:
Drum2001 wrote:
>When I use this code, it only searches one textbox. It is the one that
it uses last.. Seems like its overwrighting. This is what I have:

------------------------------------------------------------------------------------------------

Private Sub Command14_Click()
If Not IsNull(Me.Text30) Then
strWHere = "ACLike '" & Me.Text30 & "*" & "' Or "
End If

If Not IsNull(Me.Text31) Then
strWHere = "ACLike '" & Me.Text31 & "*" & "' Or "
End If


<snip>

First of all your form object naming convention, or lack of one sucks. 8)
I would be constantly wondering what Textxx and Textyy were. Debugging
time would be high in a serious application.
But to address your problem, your code is rewriting the whole of
strWhere everytime an if statement is executed. To fix what you have,
on the second if statement shown above, and all the remaining ones replace:

strWHere = "ACLike '" & Me.Text31 & "*" & "' Or "

with

strWHere = strwhere & "ACLike '" & Me.Text31 & "*" & "' Or "

That will do it.
DOH! Thanks Tim and Deluxe for spotting the logic error.
Dec 1 '06 #8
EXCELLENT!!!
THANK YOU ALL FOR YOUR ASSISTANCE!!!
Tim Marshall wrote:
Drum2001 wrote:
When I use this code, it only searches one textbox. It is the one that
it uses last.. Seems like its overwrighting. This is what I have:

------------------------------------------------------------------------------------------------
Private Sub Command14_Click()
If Not IsNull(Me.Text30) Then
strWHere = "ACLike '" & Me.Text30 & "*" & "' Or "
End If

If Not IsNull(Me.Text31) Then
strWHere = "ACLike '" & Me.Text31 & "*" & "' Or "
End If

<snip>

First of all your form object naming convention, or lack of one sucks. 8)

But to address your problem, your code is rewriting the whole of
strWhere everytime an if statement is executed. To fix what you have,
on the second if statement shown above, and all the remaining ones replace:

strWHere = "ACLike '" & Me.Text31 & "*" & "' Or "

with

strWHere = strwhere & "ACLike '" & Me.Text31 & "*" & "' Or "

That will do it.
--
Tim http://www.ucs.mun.ca/~tmarshal/
^o<
/#) "Burp-beep, burp-beep, burp-beep?" - Quaker Jake
/^^ "Be Careful, Big Bird!" - Ditto "TIM-MAY!!" - Me
Dec 1 '06 #9
salad wrote:
DOH! Thanks Tim and Deluxe for spotting the logic error.
Sorry salad, I read the post and didn't notice the "Re" - I thought it
was a first post. Didn't mean to jump in on you. 8)
--
Tim http://www.ucs.mun.ca/~tmarshal/
^o<
/#) "Burp-beep, burp-beep, burp-beep?" - Quaker Jake
/^^ "Be Careful, Big Bird!" - Ditto "TIM-MAY!!" - Me
Dec 1 '06 #10

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

Similar topics

5
by: NK | last post by:
Hi all, Does anyone know of how I can disable case sensitivity for the LIKE function in SQL? Currently the SQL statement looks like: $query = "SELECT * FROM itrader_games WHERE...
3
by: Alastair | last post by:
Hello guys, I've been building a search facility for an intranet site I'm part of developing and we've been building a search engine using Index Server. It mostly works, however there have been...
10
by: joshsackett | last post by:
I am starting an encryption project for my database and I'm performing some tests on decryption speed. A lot of my application queries use a LIKE parameter in the WHERE clause. To keep from...
2
by: Dave Smithz | last post by:
Hello there, Summary: How far can you go with SQL Select queries using like clauses with wildcard characters. Can you apply anything like regular expressions? Full details: On a Intranet...
1
by: Rick Brown | last post by:
I'm trying to scan a barcode that contains the text string "BPWOT08762" into a textbox for use in a DLookup or query grid. I want to look thru a table's field that contains the last 6 characters...
11
by: Bruce Lawrence | last post by:
Ok, I'm baffled... I'm making a query in access 97 between 2 tables. There is a field in both tables called "DWGNO". OPENORD has a record with a DWGNO of "00000012345" DIEDATA has a record...
5
by: brino | last post by:
hi all ! i want to use the "like" function in a query but i want the user to enter the search variable. i have tried "like" but this doesnt return any results for some reason. any ideas ??? ...
10
ChaseCox
by: ChaseCox | last post by:
I have a Database Called FalconAnalysis.mdb. The table I am wanting to use is called Generic Material. The Query I want to pass the value into is called Material Query. The field in the query is...
4
by: teddysnips | last post by:
I am just getting to grips with LINQ to SQL and my first attempt is to create a Search form. I need the LINQ to generate SQL like this: SELECT * FROM CustomerTable WHERE Surname LIKE 'S%' ...
0
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,...
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: 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...
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
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...
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
jinu1996
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...
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...

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.