I have this query to get record
Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset
Dim sSQL As String
sSQL = "SELECT * FROM customer where (custid = '' or custid = '" & Text1.Text & "') and (custfn = '' or custfn = '" & Text2.Text & "')"
rs.Open sSQL, cn, adOpenKeyset, adLockOptimistic
my problem is that when I do this query, text1 and text2 filter must have a value or else no result.
what I want to achieve is the user to be able to filter a result using only text1.text or text2.text and also both.
like for example if I have
1,dave
2,roman
3,nathan
if I filter using id=3 then the result should be nathan
if I filter using id=1 and custfn=nathan then there should be no result because the two record is conflicting
if I filter using custfn=roman, then it will return the id=2 and custfn=roman
how should I fix that query of mine to achieve the above result?
Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset
Dim sSQL As String
sSQL = "SELECT * FROM customer where (custid = '' or custid = '" & Text1.Text & "') and (custfn = '' or custfn = '" & Text2.Text & "')"
rs.Open sSQL, cn, adOpenKeyset, adLockOptimistic
my problem is that when I do this query, text1 and text2 filter must have a value or else no result.
what I want to achieve is the user to be able to filter a result using only text1.text or text2.text and also both.
like for example if I have
1,dave
2,roman
3,nathan
if I filter using id=3 then the result should be nathan
if I filter using id=1 and custfn=nathan then there should be no result because the two record is conflicting
if I filter using custfn=roman, then it will return the id=2 and custfn=roman
how should I fix that query of mine to achieve the above result?