Results 1 to 2 of 2
  1. #1
    Join Date
    Jun 2006

    Unanswered: Vba to mysql ( beggining of the code)

    Hello . I am still trying to connect to a mysql data base but it don´t works what is wrong?:
    Dim conn As ADODB.Connection
    Dim rs As ADODB.Recordset
    Dim cmd As ADODB.Command
    Dim teste
    Dim SQL As String
    Dim str As String
    Set rs = New ADODB.Recordset
    Set cmd = New ADODB.Command
    Set conn = New ADODB.Connection

    'I want to connect to mysql
    'Do I need the data source?

    conn.Open "driver=" & _
    "{MySQL ODBC 3.51 Driver};server=localhost;port=3306;user=root;passw ord=masterkey"
    str = "SELECT atv_0.INDICADOR FROM reincidentes.atv atv_0"

    ' I want to insert a value (variavel) into a field called (indicador)
    variavel = "insert into atv(INDICADOR)values("hdhduduh")"
    rs.Open str, conn, adOpenDynamic, adLockOptimistic

    End Sub

  2. #2
    Join Date
    Mar 2005
    When you place a variable in a sql string you have to concenate the value with "&"

    Example "Insert into atv(INDICADOR) values(" & variablename &")" and depending on the value that you are trying to insert you may want to make the string look like this

    "Insert into atv(INDICADOR) values(" & chr(34) & variablename & chr(34) &")"
    this will add quotes about the variable value.

Posting Permissions

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