0

i am connecting to a mysql table through vba in excel and i am updating it:

Set cn = New ADODB.Connection
cn.Open "DRIVER={MySQL ODBC 5.1 Driver};" & _
    "SERVER=localhost;" & _
    "DATABASE=employees;" & _
    "USER=root;" & _
    "PASSWORD=M1llen;" & _
    "Option=3"
'lets get the batch info
'
' open a recordset
Set rs = New ADODB.Recordset
rs.Open "batchinfo", cn, adOpenKeyset, adLockOptimistic, adCmdTable
' all records in a table from Report 1
'Set wsSheet1 = wbBook.Worksheets(1)
' better refer by name
'Set wsSheet1 = wbBook.Worksheets.("Report 1")
Worksheets.Item("Report 1").Select
dpath = Range("B2").Text
atime = Trim(Range("B3").Text)
rtime = Trim(Range("B4").Text)
lcalib = Trim(Range("B5").Text)
aname = Trim(Range("B6").Text)
rname = Trim(Range("B7").Text)
bstate = Trim(Range("B8").Text)

instrument = GetInstrFromXML()

With rs
    .AddNew ' create a new record
    ' add values to each field in the record
    .Fields("datapath") = "abc"
    .Fields("analysistime") = atime
    .Fields("reporttime") = rtime
    .Fields("lastcalib") = lcalib
    .Fields("analystname") = aname
    .Fields("reportname") = rname
    .Fields("batchstate") = bstate
    .Fields("instrument") = instrument
    .Update ' stores the new record
End With

the issue is that the only field that gets updated is the instrument field!!

here i a desc of the batchinfo table mysql:

mysql> desc batchinfo;
+--------------+---------+------+-----+---------+----------------+
| Field        | Type    | Null | Key | Default | Extra          |
+--------------+---------+------+-----+---------+----------------+
| rowid        | int(11) | NO   | PRI | NULL    | auto_increment |
| datapath     | text    | YES  |     | NULL    |                |
| analysistime | text    | YES  |     | NULL    |                |
| reporttime   | text    | YES  |     | NULL    |                |
| lastcalib    | text    | YES  |     | NULL    |                |
| analystname  | text    | YES  |     | NULL    |                |
| reportname   | text    | YES  |     | NULL    |                |
| batchstate   | text    | YES  |     | NULL    |                |
| instrument   | text    | YES  |     | NULL    |                |
+--------------+---------+------+-----+---------+----------------+
9 rows in set (0.00 sec)

funny thing is that when i recreate the table without the auto_increment then it works fine

i really need someone to answer this question, i dont care if you have a hunch or not exactly sure, i will try any solution

1
  • Please, please, please don't keep asking the same question over and over again. Just edit your original question. While I like Excel and VBA questions, there isn't a huge population of VBA users here to help out. You might try on some other VBA forums. Commented May 13, 2010 at 19:37

1 Answer 1

4

I'm not familiar with MySQL but TEXT looks like a blob type? If so I'm surprised it works at all as ADO requires special handling for BLOBS ( http://dev.mysql.com/tech-resources/articles/vb-blob-handling.html )

Try a VARCHAR type instead.

You could also try ADOCn.Execute "INSERT ..."

Sign up to request clarification or add additional context in comments.

4 Comments

alex thank u for your answer, why do you say its a blob? its just regular text
WOWOWOWOOW YOU ARE THE MAN!!!!!!!!!!!! IT WORKS!!!!!!!!! WOWOWOWO. can you please explain why did it work with varchar and not with text!?!??
TEXT is unlike other types like int and varchar dev.mysql.com/doc/refman/5.0/en/blob.html and probably needs to be handled differently, you'll need to ask a MySQL person about that.
thank you so so much!! ive spent 8 hours trying to figure this out!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.