Solved

using SQL with OR ??

Posted on 1999-01-16
9
155 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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 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 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…

759 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

21 Experts available now in Live!

Get 1:1 Help Now