Hi all,
I've read several topics on forum and couldn't be able to set up script to INSERT data from Excel Table specified range to Microsoft Access database over ADODB.
Currently, I am using ADODB to read data from database (material master, version of file, users), but how to do Insert thing?
I would like to insert Sheet named Material list with range:
into database table named: db_workplans
How should my code looks like?
Here below is example of my code to read data:
I've read several topics on forum and couldn't be able to set up script to INSERT data from Excel Table specified range to Microsoft Access database over ADODB.
Currently, I am using ADODB to read data from database (material master, version of file, users), but how to do Insert thing?
I would like to insert Sheet named Material list with range:
Code:
Sheet3.Range("A13", Sheet3.Range("H13").End(xlDown))
How should my code looks like?
Here below is example of my code to read data:
Code:
Private Sub MatMaster() 'GET material master from database
Dim sh As Worksheet
Set sh = ThisWorkbook.Sheets("matmaster")
sh.Rows("2:" & Rows.Count).ClearContents
Dim cnn As New ADODB.Connection
Dim rst As New ADODB.Recordset
Dim qry As String, i As Integer
Dim n As Long
qry = "SELECT * FROM db_materialmaster"
cnn.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & "URL" & ";" & "Jet OLEDB:Database Password= PASS"
rst.Open qry, cnn, adOpenKeyset, adLockOptimistic
sh.Range("A2").CopyFromRecordset rst
rst.Close
cnn.Close
Set cnn = Nothing
End Sub