Access table update

Per_

Board Regular
Joined
Sep 16, 2011
Messages
90
Hello all,

I would like to update a table with the code below. Do I need to open with different attributes to get it to work?

Please help!!

/P

VBA Code:
Dim RecordSet As ADODB.RecordSet

 Set RecordSet = New ADODB.RecordSet
 RecordSet.CursorLocation = adUseClient
        RecordSet.Open "Select Test1, Test2 from Table WHERE ID = '" & ID & "& "'", Connection, _
                 adOpenDynamic, adLockBatchOptimistic
 RecordSet.MoveFirst

RecordSet.Fields(0).Value = "TEST"   <---- Why can I not update like this? Do I need to open with different attributes?

 Set RecordSet.ActiveConnection = Connection  
 RecordSet.UpdateBatch
 RecordSet.Close
 Set RecordSet.ActiveConnection = Nothing
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
& ID & "& "'", Connection, _
You have the last ampersand in the wrong place and it's causing the rest of the line to be commented out, which is why it's green.
WHERE ID = '" & ID & "'". Connection, _ ....

Surely that raised an error that you didn't report?
 
Upvote 0

Forum statistics

Threads
1,215,842
Messages
6,127,232
Members
449,371
Latest member
strawberrish

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