title: Problem with VBA script reading from MySql database
body: <p>I am having some trouble with a vba script in Excel which should be
  reading from a MySql database.  The SQL query should only return one
  record but actually returns an empty resultset. The generated statement works fine when run through phpMyAdmin.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>Function getClientId(emailAddress As String)
      Dim rs As ADODB.Recordset
      Dim sql As String
  
      ConnectDB
  
      Set rs = New ADODB.Recordset
  
      sql = "SELECT client_id FROM clients WHERE email_address = '" &amp; emailAddress &amp; "' LIMIT 1"
      Debug.Print sql
      rs.Open sql, oConn
  
      Debug.Print rs.RecordCount
  
      If (rs.RecordCount = -1) Then
          getClientId = Null
      Else
          getClientId = rs(0)
      End If
      rs.Close
  End Function
  </code></pre>
  
  <p>EDIT: My database connect function.</p>
  
  <pre><code>Function ConnectDB()
      On Error GoTo ErrHandler
  
      Set oConn = New ADODB.Connection
      oConn.Open "DRIVER={MySQL ODBC 5.1 Driver};" &amp; _
      "SERVER=localhost;" &amp; _
      "DATABASE=mydb;" &amp; _
      "USER=user;" &amp; _
      "PASSWORD=password;" &amp; _
      "Option=3"
  
      'Debug.Print oConn
  
      Exit Function
  ErrHandler:
      MsgBox Err.Description, vbCritical, Err.Source
  End Function
  </code></pre>
  
  <p>The ConnectDB function is connecting ok as I am running other scripts
   with it.  If anyone can see what I am doing wrong then any help would
   be appreciated.</p>
  
  <p>Many thanks in advance.</p>
  
  <p>Garry</p>