VBA - Copy Excel range and paste into Access table - is it possible?

xlDude

New Member
Joined
Dec 21, 2012
Messages
7
I have a program that requires a weekly update. Excel is used as a front end application and Access is used to house the data. The people running this do not have Access but need to upload the data into it. Currrently I'm going row by row to upload the data and it's taking longer than I think it should. In fact this would be a weekly update of about 10K+ rows of data and it's taking over 30 min. It should be something like this:

Range.Copy
Table.Paste

I know it's not that simple but that's what I'm trying to do. Is it possible?

My current code:

Sub grabData

Set rs = New ADODB.Recordset
rs.Open "SELECT * FROM [Database]", cn, adOpenKeyset, adLockOptimistic, adCmdText

Set rng = dataSht.Cells.Find("Customer").Offset(1, 0)

With dataSht
Do
rs.Filter = "[Customer] = '" & .Cells(rng.Row, columns(1)).Value & "' AND " & _
"[Calendar week] = '" & .Cells(rng.Row, columns(3)).Value & "' AND " & _
"[Plant] = '" & .Cells(rng.Row, columns(4)).Value & "' AND " & _
"[Material] = '" & .Cells(rng.Row, columns(7)).Value & "'"

If rs.EOF Then
Call addThisLine
Else
Call updateThisLine
End If
Set rng = rng.Offset(1, 0)
Loop Until IsEmpty(rng) = True
End With

End Sub

Private Sub addThisLine()
With rs
.AddNew
For x = 1 To 12
rs.Fields(x - 1) = dataSht.Cells(rng.Row, columns(x))
Next x
.Update
End With
End Sub

Private Sub updateThisLine()
With rs
For x = 9 To 12
rs.Fields(x - 1) = dataSht.Cells(rng.Row, columns(x))
Next x
.Update
End With
End Sub
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.

Forum statistics

Threads
1,215,362
Messages
6,124,502
Members
449,166
Latest member
hokjock

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