pcorpz
Active Member
- Joined
- Oct 29, 2004
- Messages
- 324
SydneyGeek originally helped me with a macro that will move data from excel to access. It was flawless! Now, I am creating a new excel form, with additional columns and I've tried to modify the macro as much as I can (in my knowledge) to make it work for the new form, as I've done it before and it worked. However this time, I am coming across this runtime error: "Item cannot be found in the collection corresponding to the requested name or ordinal. "
And this is what's hilited:
Here is the macro:
Any suggestions??
And this is what's hilited:
Code:
rst(Cells(1, j).Value) = Cells(i, j).Value
Here is the macro:
Code:
Option Explicit
Const TARGET_DB = "S:\LocalFolder\Promx.mdb"
Const TARGET_TABLE = "PromoTable"
Const NUM_FIELDS = 37
Sub PushDataToAccess()
Dim sentSht As Worksheet
Dim cnn As ADODB.Connection
Dim MyConn
Dim rst As ADODB.Recordset
Dim i As Long, j As Long
Dim Rw As Long
ActiveSheet.Unprotect
Sheets("Promo").Activate
Rw = Range("A65536").End(xlUp).Row
Set cnn = New ADODB.Connection
MyConn = TARGET_DB
With cnn
.Provider = "Microsoft.Jet.OLEDB.4.0"
.Open MyConn
End With
Set rst = New ADODB.Recordset
rst.CursorLocation = adUseServer
rst.Open Source:=TARGET_TABLE, ActiveConnection:=cnn, _
CursorType:=adOpenDynamic, LockType:=adLockOptimistic, _
Options:=adCmdTable
For i = 2 To Rw
rst.AddNew
For j = 1 To NUM_FIELDS
rst(Cells(1, j).Value) = Cells(i, j).Value
Next j
rst.Update
Next i
rst.Close
cnn.Close
Set rst = Nothing
Set cnn = Nothing
Set sentSht = Sheets("SentPromo")
sentSht.Unprotect "090282"
With Sheets("Promo").Range("A1").CurrentRegion.Offset(1, 0)
.Copy Destination:=sentSht.Range("A" & Rows.Count).End(xlUp).Offset(1, 0)
.SpecialCells(xlCellTypeConstants).ClearContents
End With
sentSht.Protect "090282"
Call SendNotes
ActiveSheet.Protect
End Sub
Any suggestions??