Results 1 to 4 of 4

Thread: check if exists... *Resolved*

  1. #1
    Junior Member
    Join Date
    Jan 03
    Posts
    23

    check if exists... *Resolved*

    VB Code:
    1. Dim myConnection As ADODB.Connection    
    2. Dim Manu As ADODB.Recordset            
    3.  
    4. myConnection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & dbloc
    5. myConnection.Open
    6.  
    7. Set Manu = myConnection.Execute("SELECT * FROM installatie WHERE PC_ID LIKE text")
    8.  
    9. Myconnection.close
    10. manu.close

    The above code works fine, but i wan't a query that checks if a record excists... how do i do that?

    Thx
    Last edited by BroesWillems; May 15th, 2003 at 05:53 AM.

  2. #2
    Frenzied Member axion_sa's Avatar
    Join Date
    Jan 02
    Location
    Joburg, RSA
    Posts
    1,724
    VB Code:
    1. Dim strSQL As String
    2.  
    3. strSQL = "SELECT COUNT(*) As Cnt FROM Installatie WHERE PC_ID LIKE 'text%'"
    4. Set Manu = New ADODB.Recordset
    5. Manu.Open strSQL, myConnection
    6. If (Manu("Cnt") > 0) Then
    7.     MsgBox "Not empty"
    8. Else
    9.     MsgBox "Empty"
    10. End If
    11.  
    12. ' And your clean up code.

  3. #3
    Junior Member
    Join Date
    Jan 03
    Posts
    23
    Originally posted by axion_sa
    VB Code:
    1. Dim strSQL As String
    2.  
    3. strSQL = "SELECT COUNT(*) As Cnt FROM Installatie WHERE PC_ID LIKE 'text%'"
    4. Set Manu = New ADODB.Recordset
    5. Manu.Open strSQL, myConnection
    6. If (Manu("Cnt") > 0) Then
    7.     MsgBox "Not empty"
    8. Else
    9.     MsgBox "Empty"
    10. End If
    11.  
    12. ' And your clean up code.

    Thanks!

  4. #4
    Frenzied Member swatty's Avatar
    Join Date
    Aug 02
    Location
    somewhere on earth
    Posts
    1,476
    If you're planning to use the recordset you could check the recordcount of it.

    VB Code:
    1. Dim myConnection As ADODB.Connection    
    2.    Dim Manu As ADODB.Recordset            
    3.  
    4.    myConnection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & dbloc
    5.    myConnection.Open
    6.  
    7.    Set Manu = myConnection.Execute("SELECT * FROM installatie WHERE PC_ID LIKE 'text%'")
    8.  
    9.    If Manu.RecordCount > 0 Then
    10.       MsgBox "Installatie has " & Manu.Recordcount & " records"
    11.    Else
    12.       MsgBox "Installatie has no records with PC_ID like text"
    13.    End If
    14.    Manu.close
    15.    Myconnection.close
    Code:
    If Question = Incomplete Then
       AnswerNextOne
    Else
       ReplyIfKnown
    End If
    cu Swatty

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •