Solved

using SQL with OR ??

Posted on 1999-01-16
9
164 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 100 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Restricting text box entry from \/:?<>"| 9 76
VBA open file from excel cell 4 36
Validating VB6 Function 19 56
Added a column screws up code 5 47
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…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

914 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now