Quantcast
Channel: VBForums - Visual Basic 6 and Earlier
Viewing all articles
Browse latest Browse all 22080

Why does this if statement not work?

$
0
0
Hi guys, I am using the current code below, now i'm trying to make it search the database for what is typed in text1.text and then when it finds the results it adds them to listview4.

For some reason when i search it comes back with 'No results found' (The else statement)
even though it is defo in the database.

Anyone have any ideas why this is happening?

thanks
jamie

Code:

Dim db As Database
Dim rs As Recordset
Dim ds As Recordset
Dim WS As Workspace

Dim dbfile As Variant
Dim pwdstring As Variant

 Set WS = DBEngine.Workspaces(0)
    dbfile = ("\\server\Database\maindb.mdb")
pwdstring = "C123"
Set db = DBEngine.OpenDatabase(dbfile, False, False, ";PWD=" & pwdstring)

Set rs = db.OpenRecordset("SELECT * FROM `Leads` WHERE `Company Name` LIKE UCASE('%" & Text1.Text & "%') OR `Contact Name` LIKE UCASE('%" & Text1.Text & "%') OR `Phone Number` LIKE UCASE('%" & Text1.Text & "%') OR `Contact Number2` LIKE UCASE('%" & Text1.Text & "%') OR `Mobile` LIKE UCASE('%" & Text1.Text & "%')")



If Not (rs.EOF And rs.BOF) Then


Do While Not rs.EOF




ListView1.ListItems.Clear



Dim lvwItem8 As ListItem

       
 
     
 
        Set lvwItem8 = ListView1.ListItems.Add(, , rs.Fields.Item("Contact Name").value)
        lvwItem8.SubItems(1) = rs.Fields.Item("Company Name").value
     
lvwItem8.SubItems(2) = rs.Fields.Item("Status").value
     
lvwItem8.SubItems(3) = rs.Fields.Item("Phone Number").value


lvwItem8.SubItems(4) = rs.Fields.Item("leadid").value
           



lvwItem8.SubItems(5) = rs.Fields.Item("Calling From").value
           


           
    rs.MoveNext
Loop
rs.Close

  Else
MsgBox "No results found"
   
    End If


Viewing all articles
Browse latest Browse all 22080

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>