i still not understand.
how ever i using mdb database
Main Topics
Browse All Topicsbelow here is my code for sql
but it has error.
please amend it for me and i will pose the points to you all.
error code is 3075
Dim strWhere As String
Dim strWhere1 As String
Dim strWhere2 As String
Dim strWhere3 As String
Dim strWhere5 As String
Dim strWhere6 As String
Dim strWhere7 As String
If Len(Trim$(pcuser.Text)) > 0 Then 'First field Query
strWhere = "WHERE name LIKE " & Chr$(34) & pcuser.Text & "*" & Chr$(34)
End If
If Len(Trim$(pcid.Text)) > 0 Then 'Second field Query
If Len(strWhere) = 0 Then
strWhere1 = "WHERE id LIKE " & Chr$(34) & pcid.Text & "*" & Chr$(34)
Else
strWhere1 = "AND id LIKE " & Chr$(34) & pcid.Text & "*" & Chr$(34)
End If
End If
If Len(Trim$(pcdept.Text)) > 0 Then 'third field Query
If Len(strWhere) = 0 Then
strWhere2 = "WHERE dept LIKE " & Chr$(34) & pcdept.Text & "*" & Chr$(34)
Else
strWhere2 = "AND dept LIKE " & Chr$(34) & pcdept.Text & "*" & Chr$(34)
End If
End If
If Len(Trim$(pcmonitor.Text))
If Len(strWhere) = 0 Then
strWhere3 = "WHERE monitor LIKE " & Chr$(34) & pcmonitor.Text & "*" & Chr$(34)
Else
strWhere3 = " AND monitor LIKE " & Chr$(34) & pcmonitor.Text & "*" & Chr$(34)
End If
End If
If Len(Trim$(pccpu.Text)) > 0 Then 'Tujuh field Query
If Len(strWhere) = 0 Then
strWhere4 = "WHERE cpu LIKE " & Chr$(34) & pccpu.Text & "*" & Chr$(34)
Else
strWhere4 = " AND cpu LIKE " & Chr$(34) & pccpu.Text & "*" & Chr$(34)
End If
End If
If Len(Trim$(pcsmonitor.Text)
If Len(strWhere) = 0 Then
strWhere5 = "WHERE serialmoNITOR LIKE " & Chr$(34) & pcsmonitor.Text & "*" & Chr$(34)
Else
strWhere5 = " AND serialmoNITOR LIKE " & Chr$(34) & pcsmonitor.Text & "*" & Chr$(34)
End If
End If
If Len(Trim$(pcscpu.Text)) > 0 Then 'Empat Belas Field Query
If Len(strWhere) = 0 Then
strWhere6 = "WHERE serialCpu LIKE " & Chr$(34) & pcscpu.Text & "*" & Chr$(34)
Else
strWhere6 = " AND serialcpu LIKE " & Chr$(34) & pcscpu.Text & "*" & Chr$(34)
End If
End If
If Len(Trim$(pcuserkey.Text))
If Len(strWhere) = 0 Then
strWhere7 = "WHERE USERKEY LIKE " & Chr$(34) & pcuserkey.Text & "*" & Chr$(34)
Else
strWhere7 = " AND USERKEY LIKE " & Chr$(34) & pcuserkey.Text & "*" & Chr$(34)
End If
End If
dataf.datapc.RecordSource = "SELECT * FROM PCREPORTDB " & strWhere & strWhere1 & strWhere2 _
& strWhere3 & strWhere4 & strWhere5 & strWhere6 & strWhere7 & "ORDER BY " & Text1.Text
dataf.datapc.Refresh
dataf.datapc.Recordset.Rec
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
you'll get a problem if strWhere="" because strWhere1-7 will have a WHERE clause ...
if you change the else statement to:
strWhere = strWhere & " AND ......"
it should work
-----------
If Len(Trim$(pcuser.Text)) > 0 Then 'First field Query
strWhere = "WHERE name LIKE " & Chr$(34) & pcuser.Text & "*" & Chr$(34)
End If
If Len(Trim$(pcid.Text)) > 0 Then 'Second field Query
If Len(strWhere) = 0 Then
strWhere = "WHERE id LIKE " & Chr$(34) & pcid.Text & "*" & Chr$(34)
Else
strWhere = strWhere & "AND id LIKE " & Chr$(34) & pcid.Text & "*" & Chr$(34)
End If
End If
If Len(Trim$(pcdept.Text)) > 0 Then 'third field Query
If Len(strWhere) = 0 Then
strWhere = "WHERE dept LIKE " & Chr$(34) & pcdept.Text & "*" & Chr$(34)
Else
strWhere2 = strWhere & "AND dept LIKE " & Chr$(34) & pcdept.Text & "*" & Chr$(34)
End If
End If
.... etc.
--------------
dataf.datapc.RecordSource = "SELECT * FROM PCREPORTDB " & strWhere & " ORDER BY " & Text1.Text
you'll get a problem if strWhere="" because strWhere1-7 will have a WHERE clause ...
if you change the else statement to:
strWhere = strWhere & " AND ......"
it should work
-----------
If Len(Trim$(pcuser.Text)) > 0 Then 'First field Query
strWhere = "WHERE name LIKE " & Chr$(34) & pcuser.Text & "*" & Chr$(34)
End If
If Len(Trim$(pcid.Text)) > 0 Then 'Second field Query
If Len(strWhere) = 0 Then
strWhere = "WHERE id LIKE " & Chr$(34) & pcid.Text & "*" & Chr$(34)
Else
strWhere = strWhere & "AND id LIKE " & Chr$(34) & pcid.Text & "*" & Chr$(34)
End If
End If
If Len(Trim$(pcdept.Text)) > 0 Then 'third field Query
If Len(strWhere) = 0 Then
strWhere = "WHERE dept LIKE " & Chr$(34) & pcdept.Text & "*" & Chr$(34)
Else
strWhere2 = strWhere & "AND dept LIKE " & Chr$(34) & pcdept.Text & "*" & Chr$(34)
End If
End If
.... etc.
--------------
dataf.datapc.RecordSource = "SELECT * FROM PCREPORTDB " & strWhere & " ORDER BY " & Text1.Text
to ninibini.
can you put it in whole code.
so i just copy and paste it to my form.
because i still not understand.
where my another strwhere 1 and 3 to 7 ?
for the second search,
why do u put
If Len(Trim$(pcdept.Text)) > 0 Then 'third field Query
If Len(strWhere) = 0 Then
strWhere = "WHERE dept LIKE " & Chr$(34) & pcdept.Text & "*" & Chr$(34)
Else
strWhere2 = strWhere & "AND dept LIKE " & Chr$(34) & pcdept.Text & "*" & Chr$(34)
End If
End If
wheres my strwhere1 ?
thanks.
you won't need strWhere[1-7] anymore, because each search criteria is added directly to the existing strWhere (strWhere = strWhere & " AND ..." or in case strWhere is still empty - strWhere= " WHERE ...")
the strWhere2 in the comment above was a typing(or better editing ) error - sorry :)
--------------------------
Dim strWhere As String
strWhere=""
If Len(Trim$(pcuser.Text)) > 0 Then 'First field Query
strWhere = "WHERE name LIKE " & Chr$(34) & pcuser.Text & "*" & Chr$(34)
End If
If Len(Trim$(pcid.Text)) > 0 Then 'Second field Query
If Len(strWhere) = 0 Then
strWhere = "WHERE id LIKE " & Chr$(34) & pcid.Text & "*" & Chr$(34)
Else
strWhere = strWhere & " AND id LIKE " & Chr$(34) & pcid.Text & "*" & Chr$(34)
End If
End If
If Len(Trim$(pcdept.Text)) > 0 Then 'third field Query
If Len(strWhere) = 0 Then
strWhere = "WHERE dept LIKE " & Chr$(34) & pcdept.Text & "*" & Chr$(34)
Else
strWhere =strWhere & " AND dept LIKE " & Chr$(34) & pcdept.Text & "*" & Chr$(34)
End If
End If
If Len(Trim$(pcmonitor.Text))
If Len(strWhere) = 0 Then
strWhere = "WHERE monitor LIKE " & Chr$(34) & pcmonitor.Text & "*" & Chr$(34)
Else
strWhere = strWhere & " AND monitor LIKE " & Chr$(34) & pcmonitor.Text & "*" & Chr$(34)
End If
End If
If Len(Trim$(pccpu.Text)) > 0 Then 'Tujuh field Query
If Len(strWhere) = 0 Then
strWhere = "WHERE cpu LIKE " & Chr$(34) & pccpu.Text & "*" & Chr$(34)
Else
strWhere = strWhere & " AND cpu LIKE " & Chr$(34) & pccpu.Text & "*" & Chr$(34)
End If
End If
If Len(Trim$(pcsmonitor.Text)
If Len(strWhere) = 0 Then
strWhere = "WHERE serialmoNITOR LIKE " & Chr$(34) & pcsmonitor.Text & "*" & Chr$(34)
Else
strWhere = strWhere & " AND serialmoNITOR LIKE " & Chr$(34) & pcsmonitor.Text & "*" & Chr$(34)
End If
End If
If Len(Trim$(pcscpu.Text)) > 0 Then 'Empat Belas Field Query
If Len(strWhere) = 0 Then
strWhere = "WHERE serialCpu LIKE " & Chr$(34) & pcscpu.Text & "*" & Chr$(34)
Else
strWhere = strWhere & " AND serialcpu LIKE " & Chr$(34) & pcscpu.Text & "*" & Chr$(34)
End If
End If
If Len(Trim$(pcuserkey.Text))
If Len(strWhere) = 0 Then
strWhere = "WHERE USERKEY LIKE " & Chr$(34) & pcuserkey.Text & "*" & Chr$(34)
Else
strWhere =strWhere & " AND USERKEY LIKE " & Chr$(34) & pcuserkey.Text & "*" & Chr$(34)
End If
End If
dataf.datapc.RecordSource = "SELECT * FROM PCREPORTDB " & strWhere & "ORDER BY " & Text1.Text
dataf.datapc.Refresh
dataf.datapc.Recordset.Rec
Business Accounts
Answer for Membership
by: angelIIIPosted on 2000-11-11 at 02:25:35ID: 5257160
I first thougt that you had missed a space before the word WHERE , but it might be a missing space before the ORDER BY. , "''" ) & "*" & Chr$(34)
Anyway, you might run into trouble whenever a user enters a ' (chr(34) in any of the text boxes.
adjust it like this (replace any single quote <'> by 2 single quotes <''>):
LIKE " & Chr$(34) & replace(pcuserkey.Text,"'"
For more information, we need to know which database you're working with...