Solved

using SQL with OR ??

Posted on 1999-01-16
9
171 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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Input past end of file vbs script 9 92
Run code from text file in vb 1 64
message box in access 4 46
Automatic Email Reminder 4 36
I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…

776 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