Guest User

Untitled

a guest
Aug 10th, 2018
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. ODBC MySQL from VBA throwing error
  2. Sub WriteToDatabase(AccessionID As String)
  3. On Error GoTo DBError
  4. Set oRS = New ADODB.Recordset
  5. dateTime = CStr(Now)
  6. state = "In Progress 1"
  7. strSQL = "INSERT INTO track (AccID, DateTime, Gender,State,Proc1BatchID,Proc2BatchID) " & _
  8. "VALUES ('" & esc(AccID) & "', " & _
  9. "'" & esc(dateTime) & "'," & _
  10. "'NULL'," & _
  11. "'" & esc(state) & "', " & _
  12. "'NULL'," & _
  13. "'NULL'," & _
  14. "'NULL')"
  15. oRS.Open strSQL, oConn, adOpenDynamic, adLockOptimistic
  16.  
  17. If Not oRS Is Nothing Then Set oRS = Nothing
  18. If Not oConn Is Nothing Then Set oConn = Nothing
  19. rs.Close
  20. oRS.Close
  21. oConn.Close
  22. DBError:
  23. MsgBox "Error " & Err.Number & ": " & Err.Description, vbCritical
  24. End Sub
  25. Sub ConnectToDatabase()
  26. Set oConn = New ADODB.Connection
  27. oConn.Open "DRIVER={MySQL ODBC 3.51 Driver};" & _
  28. "SERVER=127.0.0.1;" & _
  29. "DATABASE=phase1;" & _
  30. "USER=root;" & _
  31. "PASSWORD=pass;" & _
  32. "PORT=3306;" & _
  33. "Option=3"
  34. End Sub
  35. Function esc(txt As String)
  36. esc = Trim(Replace(txt, "'", "'"))
  37. End Function
Add Comment
Please, Sign In to add comment