push to access macro help!

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:
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??
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Nevermind everyone! Found out the issue! I missed one column to add on access! :)
 
Upvote 0

Forum statistics

Threads
1,223,214
Messages
6,170,772
Members
452,353
Latest member
strainu

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