Excel not writing to MySQL db

Nimrod

MrExcel MVP
Joined
Apr 29, 2002
Messages
6,259
I'm able to download data from MySQL to excel but cant write data back to MySQL.... can anyone see what Im doing wrong ? Pleeeassee :roll:

Public Sub MySQL_DAO_AddRecs()
Dim ws As Workspace
Dim conn As Connection
'Dim queryDef As queryDef
Dim RS As Recordset
'Dim cl As rdoColumn




'connect to MySQL using MySQL ODBC 3.51 Driver
Set ws = DBEngine.CreateWorkspace("", "root", "root", dbUseODBC)


InfoStr = "ODBC;DSN=ResourceView;DESC=MySQL ODBC 3.51 Driver DSN;DATABASE=ResourceView;SERVER=localhost;UID=root;PASSWORD=;PORT=3306;OPTION=3;STMT=;"

' connect to Database
Set conn = ws.OpenConnection("ResourceView", dbDriverNoPrompt, False, InfoStr)

' connect to Table of database
Set RS = conn.OpenRecordset("Assignments", dbOpenDynamic)

' Move to the first row of the recordset.
RS.MoveFirst

With ThisWorkbook.Sheets("Data")
For Each c In .Columns("A:A").SpecialCells(xlCellTypeConstants, 2)
Col = Col + 1

RS.AddNew


RS!Tasks = Trim(.Cells(1, Col).Value)
RS!Project = Trim(.Cells(2, Col).Value)
' NOTE THIS IS THE DATE MANDITORY DATE FORMAT IN MYSQL
RS!StartDate = Format(Trim(.Cells(3, Col).Value), "yyyy-mm-dd") ' NOTE THIS IS THE DATE MANDITORY DATE FORMAT IN MYSQL
RS!DueDate = Format(Trim(.Cells(4, Col).Value), "yyyy-mm-dd")
RS!DropDeadDate = Format(Trim(.Cells(5, Col).Value), "yyyy-mm-dd")
RS!EstimateHrs = Trim(.Cells(6, Col).Value)
RS!Priority = Trim(.Cells(7, Col).Value)
RS!Static = Trim(.Cells(8, Col).Value)
RS!WkND = Trim(.Cells(9, Col).Value)
RS!PercentCompl = Trim(.Cells(10, Col).Value)
RS!ActualHrs = Trim(.Cells(11, Col).Value)
RS!Status = Trim(.Cells(12, Col).Value)
RS!Initiative = Trim(.Cells(13, Col).Value)
RS!Descript = Trim(.Cells(14, Col).Value)
RS!Depend = Trim(.Cells(15, Col).Value)
RS!FollowUp = Trim(.Cells(16, Col).Value)
RS!Details = Trim(.Cells(17, Col).Value)
RS!Risks = Trim(.Cells(18, Col).Value)
RS!CTA = Trim(.Cells(19, Col).Value)
RS!TaskOwner = Trim(.Cells(20, Col).Value)
RS!OOOVO = Trim(.Cells(21, Col).Value)




RS.Update

' Move to the next record.
RS.MoveNext

Next c
End With
' Close the Recordset object.
RS.Close






End Sub
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
I took a brief look at your code.

I have never interfaced with MySql, but have worked
a lot with DAO. On the surface, what you are doing seems
straight forward.

You may not need to use the
rs.movenext
command at the end of your loop.
(the rs.addnew at the top of the loop creates a new record).

What type of errors are you getting when
you run this code?

Also, I am curious, why are you interfacing MySql with Excel?
 
Upvote 0

Forum statistics

Threads
1,223,536
Messages
6,172,897
Members
452,488
Latest member
jamesgeorgewalker

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top