?
Solved

using SQL with OR ??

Posted on 1999-01-16
9
Medium Priority
?
197 Views
Last Modified: 2010-05-03
i would like to make a statement like this
sSql = "SELECT * FROM Makpel" & _
       "WHERE nama = '" & Text1.Text & "' &" _
       "OR namabapa = '"&Text4.Text&"' " & _
       "ORDER BY nama"
that is if the record match any text value the record will be display
0
Comment
Question by:pohkheng1
  • 3
  • 3
  • 3
9 Comments
 

Author Comment

by:pohkheng1
ID: 1468947
Adjusted points to 100
0
 
LVL 3

Accepted Solution

by:
a111a111a111 earned 300 total points
ID: 1468948
sSql = "SELECT * FROM Makpel WHERE Name = Text1.Text OR nama = Text4.text ORDER BY nama"
0
 
LVL 7

Expert Comment

by:Dedushka
ID: 1468949
Hi, pohkheng1!

Assume, Text1 contains "xxxxx" and Text4 contains "yyyyy". The final SQL string, that will pass to DBMS should be:
---------
SELECT * FROM Makpel WHERE nama = "xxxxx" OR namabapa = "yyyyy" ORDER BY nama;
---------

To create this SQL use following code:

sSql = "SELECT * FROM Makpel" & _
       " WHERE nama = " & _     'space before WHERE
       Chr(34) & Text1.Text & Chr(34) & _
       " OR namabapa = " & _    'space before OR
       Chr(34) & Text4.Text & Chr(34) & _
       " ORDER BY nama;"        'space before ORDER

Cheers,
Dedushka
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Expert Comment

by:a111a111a111
ID: 1468950
Correction:

Sql = "SELECT * FROM Makpel" & _
           "WHERE nama = '" & & CStr(Text1.Text) & "' &" _
           "OR namabapa = '" & & CStr(Text4.Text) &"' " & _
           "ORDER BY nama"

the key is
"WHERE NNNN = " & CStr(text1.text) & "
0
 

Author Comment

by:pohkheng1
ID: 1468951
Dedushka sql seems to have error coming out
it run rime error 3061
it say to few parameters. Expected 1
solve this and u gain the point
0
 
LVL 3

Expert Comment

by:a111a111a111
ID: 1468952
Hi again,
your Field nama or namabapa as not spell correct or CASE sensitive.

OR your TABLE is not spell correctly: is it Makpel?


The help on this error say:
This parameter query requires the specified number of parameters, which you didn't supply. Provide the expected number of parameters, and run the query again.
In some cases, this message is generated when unknown field names or expressions are interpreted as query parameters. Be sure to enclose field names containing spaces or punctuation with square brackets [ ].  

So check your database for the correct table AND field names!

0
 
LVL 7

Expert Comment

by:Dedushka
ID: 1468953
pohkheng1,
remove comments from code and use it, i.e.:
sSql = "SELECT * FROM Makpel" & _
       " WHERE nama = " & _
       Chr(34) & Text1.Text & Chr(34) & _
       " OR namabapa = " & _
       Chr(34) & Text4.Text & Chr(34) & _
       " ORDER BY nama;"

Good luck,
Dedushka
0
 

Author Comment

by:pohkheng1
ID: 1468954
thanks a lot
0
 
LVL 7

Expert Comment

by:Dedushka
ID: 1468955
pohkheng1,
sorry, i don't understand.
You say me "thanks" and give point to a111a111a111?
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question