pohkheng1
asked on
using SQL with OR ??
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
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
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
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) & "
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) & "
ASKER
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
it run rime error 3061
it say to few parameters. Expected 1
solve this and u gain the point
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!
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!
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
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
ASKER
thanks a lot
pohkheng1,
sorry, i don't understand.
You say me "thanks" and give point to a111a111a111?
sorry, i don't understand.
You say me "thanks" and give point to a111a111a111?
ASKER